Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
80
Task/Penneys-game/Phix/penneys-game.phix
Normal file
80
Task/Penneys-game/Phix/penneys-game.phix
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
function trio(integer pick)
|
||||
return substitute_all(sprintf("%03b",pick),"10","HT")
|
||||
end function
|
||||
|
||||
function getuser(integer bot)
|
||||
integer user
|
||||
while 1 do
|
||||
user = 8 -- (a bit that clears after 3 shifts)
|
||||
printf(1,"Enter your sequence of 3 (H/T):");
|
||||
while user>7 do
|
||||
integer c = upper(wait_key())
|
||||
if c=#1B then abort(0) end if -- (Escape)
|
||||
if find(c,"HT") then
|
||||
puts(1,c)
|
||||
user = and_bits(user*2+(c='H'),0b111111)
|
||||
end if
|
||||
end while
|
||||
if user!=bot then exit end if
|
||||
printf(1,"\nYou may not pick the same as Robort!\n")
|
||||
end while
|
||||
printf(1,"\n")
|
||||
return user
|
||||
end function
|
||||
|
||||
function getbot(int user)
|
||||
int bot = iff(user=-1?rand(8)-1
|
||||
:4-and_bits(user,2)*2+floor(user/2))
|
||||
printf(1,"Robort picks %s\n", {trio(bot)})
|
||||
return bot
|
||||
end function
|
||||
|
||||
function rungame(integer user, bot)
|
||||
/* We only need to store the last 3 tosses, as 0..7 */
|
||||
int last3 = rand(8)-1
|
||||
|
||||
printf(1,"Rolling: %s",{trio(last3)})
|
||||
while 1 do
|
||||
if user=last3 then
|
||||
printf(1,"\nUser wins!\n")
|
||||
return 1
|
||||
elsif bot=last3 then
|
||||
printf(1,"\nRobort wins!\n")
|
||||
return 0
|
||||
end if
|
||||
last3 = and_bits(last3,3)*2+(rand(2)=1)
|
||||
printf(1,"%c", iff(and_bits(last3,1) ? 'H' : 'T'))
|
||||
sleep(0.5)
|
||||
end while
|
||||
end function
|
||||
|
||||
procedure main()
|
||||
integer playerwins = 0,
|
||||
totalgames = 0,
|
||||
robortwins = 0
|
||||
|
||||
/* Just use ctrl-c or Escape to exit */
|
||||
while 1 do
|
||||
integer user = -1,
|
||||
bot = -1
|
||||
|
||||
printf(1,"\n")
|
||||
if rand(2)=1 then
|
||||
bot = getbot(-1)
|
||||
user = getuser(bot)
|
||||
else
|
||||
user = getuser(-1)
|
||||
bot = getbot(user)
|
||||
end if
|
||||
|
||||
playerwins += rungame(user, bot)
|
||||
totalgames += 1
|
||||
robortwins = totalgames-playerwins
|
||||
|
||||
printf(1,"Robort:%d You:%d out of %d games\n",
|
||||
{robortwins, playerwins, totalgames})
|
||||
printf(1,"==================================\n")
|
||||
end while
|
||||
|
||||
end procedure
|
||||
main()
|
||||
Loading…
Add table
Add a link
Reference in a new issue