Jump to content

Pig the dice game/Player: Difference between revisions

no edit summary
No edit summary
Line 2,006:
98 97 96 95 93 92 91 90 89 87 86 85 84 82 81 80 78 77 75</lang>
This is a table of decision points. First row represents sum of our current uncommitted rolls. Second row represents the maximum permanent score where you should roll again with that number of uncommitted points, if we are using this estimation mechanism to choose our actions. Note that the first four columns here should have some obvious validity -- for example, if we have 96 permanent points and we have rolled 4 uncommitted points, we have won the game and we gain nothing from rerolling... Note also that this decision mechanism says we should never reroll if we have at least 20 uncommitted points.
 
=={{header|M2000 Interpreter}}==
Strategy like ADA, look if get 8 or morte points and then look if other sum is lower from 100 from a min difference, and if it is true the choose Hold, else continue until win or dice=1.
 
<lang M2000 Interpreter>
Module GamePig {
Print "Game of Pig"
dice=-1
res$=""
Player1points=0
Player1sum=0
Player2points=0
Player2sum=0
HaveWin=False
\\ strategy
Max_Points=8
Min_difference=10
score()
\\ for simulation
simulate$=String$("R", 500)
Keyboard simulate$
\\ end simulation
while res$<>"Q" {
Print "Player 1 turn"
PlayerTurn(&Player1points, &player1sum, player2sum)
if res$="Q" then exit
Player1sum+=Player1points
Score()
Print "Player 2 turn"
PlayerTurn(&Player2points,&player2sum, player1sum)
if res$="Q" then exit
Player2sum+=Player2points
Score()
}
If HaveWin then {
Score()
If Player1Sum>Player2sum then {
Print "Player 1 Win"
} Else Print "Player 2 Win"
}
Sub Rolling()
dice=random(1,6)
Print "dice=";dice
End Sub
Sub PlayOrQuit()
Print "R - Roling Q-Quit"
Repeat {
res$=Ucase$(Key$)
} Until Instr("RQ", res$)>0
End Sub
Sub PlayAgain()
Print "R - Roling H - Hold Q-Quit"
Repeat {
res$=Ucase$(Key$)
} Until Instr("RHQ", res$)>0
End Sub
Sub PlayerTurn(&playerpoints, &sum, othersum)
PlayOrQuit()
If res$="Q" then Exit Sub
playerpoints=0
Rolling()
While dice<>1 and res$="R" {
playerpoints+=dice
if dice>1 and playerpoints+sum>100 then {
sum+=playerpoints
HaveWin=True
res$="Q"
} Else {
if playerpoints>=Max_Points Then If 100-othersum>Min_difference Then res$="H" : exit
PlayAgain()
if res$="R" then Rolling()
}
}
if dice=1 then playerpoints=0
End Sub
Sub Score()
Print "Player1 points="; Player1sum
Print "Player2 points="; Player2sum
End Sub
}
GamePig
 
</lang>
 
=={{header|Perl 6}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.