Bash脚本用于执行Java控制台应用程序。

huangapple go评论74阅读模式
英文:

Bash script to execute Java console application

问题

我有一个Java控制台应用程序,它接受用户输入并根据输入执行操作。以下是示例:

**派彩表            倍数**
=======================================
皇家同花顺   |       250
同花顺       |       50
四条         |       25
葫芦         |       9
同花         |       6
顺子         |       5
三条         |       3
两对         |       2
一对(王对) |       1

-----------------------------------
余额:$500
输入赌注:

我必须输入赌注金额:

输入赌注: 300

手牌:[K黑桃,J黑桃,10梅花,9方块,J红心]
输入要保留的卡牌位置(例如:1 4 5):

输入要保留的卡牌位置(例如:1 4 5):
3

保留的卡牌:[10梅花]
新手牌:[10梅花,5梅花,10红心,A方块,10方块]

**三条**

您的余额:$1400
还要再玩一局吗(y或n)?

y

我只需要一个想法,一个用于自动化这个手动过程的bash脚本。


<details>
<summary>英文:</summary>

I have a Java console application which accepts the user input and performs action based on the input. Below is the sample:

```none
**Payout Table          Multiplier**
=======================================
Royal Flush     |       250
Straight Flush  |       50
Four of a Kind  |       25
Full House      |       9
Flush           |       6
Straight        |       5
Three of a Kind |       3
Two Pairs       |       2
Royal Pair      |       1

-----------------------------------
Balance: $500
Enter bet:

I have to enter the amount to bet with:

Enter bet: 300

HAND: [K Spades, J Spades, 10 Clubs, 9 Diamonds, J Hearts]  
Enter positions of cards to keep (e.g. 1 4 5):

Enter positions of cards to keep (e.g. 1 4 5):  
3

Held Cards: [10 Clubs]  
NEW HAND: [10 Clubs, 5 Clubs, 10 Hearts, A Diamonds, 10 Diamonds]

**Three of a Kind**

Your balance: $1400  
One more game (y or n)?

y

I just need help with an idea of a bash script to automate this manual process.

答案1

得分: 1

根据您想要输入的不同情况的复杂程度,您可能可以使用 `expect`:
https://linux.die.net/man/1/expect

类似问题的示例:
https://stackoverflow.com/questions/4780893/use-expect-in-a-bash-script-to-provide-a-password-to-an-ssh-command

示例:

#!/usr/bin/expect
eval spawn java Main

# 可能需要调整提示以更好地匹配
interact -o -nobuffer -re "Enter bet: " return
send "300\r"
interact -o -nobuffer -re "Enter positions of cards to keep (e.g. 1 4 5):\r" return
send "3\r"
interact -o -nobuffer -re "One more game (y or n)?" return
send "y\r"
interact
英文:

Depending on the complexity of the different cases that you would like to enter, you might be able to use expect:
https://linux.die.net/man/1/expect

Example for a similar problem:
https://stackoverflow.com/questions/4780893/use-expect-in-a-bash-script-to-provide-a-password-to-an-ssh-command

Example:

#!/usr/bin/expect
eval spawn java Main

# May need to adjust prompts to match better
interact -o -nobuffer -re &quot;Enter bet: &quot; return
send &quot;300\r&quot;
interact -o -nobuffer -re &quot;Enter positions of cards to keep (e.g. 1 4 5):\r&quot; return
send &quot;3\r&quot;
interact -o -nobuffer -re &quot;One more game (y or n)?&quot; return
send &quot;y\r&quot;
interact

huangapple
  • 本文由 发表于 2020年10月20日 02:41:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/64433349.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定