Data update
This commit is contained in:
parent
5150844a7d
commit
4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions
|
|
@ -1,108 +0,0 @@
|
|||
with Ada.Text_IO;
|
||||
with Ada.Numerics.Discrete_Random;
|
||||
|
||||
procedure Game_21 is
|
||||
|
||||
procedure Put (Item : String) is
|
||||
begin
|
||||
for Char of Item loop
|
||||
Ada.Text_IO.Put (Char);
|
||||
delay 0.010;
|
||||
end loop;
|
||||
end Put;
|
||||
|
||||
procedure New_Line is
|
||||
begin
|
||||
Ada.Text_IO.New_Line;
|
||||
end New_Line;
|
||||
|
||||
procedure Put_Line (Item : String) is
|
||||
begin
|
||||
Put (Item);
|
||||
New_Line;
|
||||
end Put_LIne;
|
||||
|
||||
type Player_Kind is (Human, Computer);
|
||||
type Score_Type is range 0 .. 21;
|
||||
subtype Amount_Range is Score_Type range 1 .. 3;
|
||||
|
||||
package Amount_Generators is
|
||||
new Ada.Numerics.Discrete_Random (Amount_Range);
|
||||
|
||||
Gen : Amount_Generators.Generator;
|
||||
Total : Score_Type := 0;
|
||||
Choice : Character;
|
||||
Player : Player_Kind;
|
||||
Amount : Amount_Range;
|
||||
begin
|
||||
Amount_Generators.Reset (Gen);
|
||||
|
||||
Put_Line ("--- The 21 Game ---"); New_Line;
|
||||
|
||||
Put ("Who is starting human or computer (h/c) ? ");
|
||||
Ada.Text_IO.Get_Immediate (Choice);
|
||||
New_Line;
|
||||
|
||||
case Choice is
|
||||
when 'c' | 'C' => Player := Computer;
|
||||
when 'h' | 'H' => Player := Human;
|
||||
when others => return;
|
||||
end case;
|
||||
|
||||
Play_Loop : loop
|
||||
New_Line;
|
||||
Put ("Runing total is "); Put (Total'Image); New_Line;
|
||||
New_Line;
|
||||
|
||||
case Player is
|
||||
|
||||
when Human =>
|
||||
Put_Line ("It is your turn !");
|
||||
Input_Loop : loop
|
||||
Put ("Enter choice 1 .. 3 (0 to end) : ");
|
||||
Ada.Text_IO.Get_Immediate (Choice);
|
||||
|
||||
case Choice is
|
||||
when '1' .. '3' =>
|
||||
Amount := Amount_Range'Value ("" & Choice);
|
||||
exit Input_Loop;
|
||||
|
||||
when '0' =>
|
||||
exit Play_Loop;
|
||||
|
||||
when others =>
|
||||
Put_Line ("Choice must be in 1 .. 3");
|
||||
end case;
|
||||
end loop Input_Loop;
|
||||
New_Line;
|
||||
|
||||
when Computer =>
|
||||
delay 1.500;
|
||||
Amount := Amount_Generators.Random (Gen);
|
||||
Put ("Computer chooses: "); Put (Amount'Image); New_Line;
|
||||
delay 0.800;
|
||||
|
||||
end case;
|
||||
|
||||
New_Line;
|
||||
Amount := Score_Type'Min (Amount, Score_Type'Last - Total);
|
||||
Put (" "); Put (Total'Image); Put (" + "); Put (Amount'Image); Put (" = ");
|
||||
Total := Total + Amount;
|
||||
Put (Total'Image);
|
||||
New_Line;
|
||||
|
||||
if Total = 21 then
|
||||
New_Line;
|
||||
Put ("... and we have a WINNER !!"); New_Line;
|
||||
delay 0.500;
|
||||
Put_Line (" ... and the winner is ...");
|
||||
delay 1.000;
|
||||
Put_Line (" " & Player'Image);
|
||||
exit;
|
||||
end if;
|
||||
|
||||
Player := (case Player is
|
||||
when Computer => Human,
|
||||
when Human => Computer);
|
||||
end loop Play_Loop;
|
||||
end Game_21;
|
||||
|
|
@ -5,7 +5,7 @@ print "-----------------------------"
|
|||
players: ["A" "B"]
|
||||
currentPlayer: sample players
|
||||
nextPlayer: first players -- currentPlayer
|
||||
runningTotal: new 0
|
||||
runningTotal: 0
|
||||
num: 0
|
||||
|
||||
getNum: function [][
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ Gui, add, text, xs vT, Total : 00
|
|||
Gui, add, text, xs vComputer, Computer Dealt 00
|
||||
Gui, add, text, xs Section, Player 1
|
||||
loop, 3
|
||||
Gui, add, button, x+5 vPlayer1_%A_Index% gTotal, % A_Index
|
||||
Gui, add, button, x+5 vPlayer1_%A_Index% gTotal, % A_Index
|
||||
Gui, add, button, xs vReset gReset, reset
|
||||
Gui show,, 21 Game
|
||||
Winners := [1,5,9,13,17,21]
|
||||
|
|
@ -18,13 +18,13 @@ total := 0
|
|||
GuiControl,, T, % "Total : " SubStr("00" Total, -1)
|
||||
GuiControl,, Computer, % "Computer Waiting"
|
||||
Loop 3
|
||||
GuiControl, Enable, % "Player1_" A_Index
|
||||
GuiControl, Enable, % "Player1_" A_Index
|
||||
Random, rnd, 0, 1
|
||||
if rnd
|
||||
{
|
||||
Loop 3
|
||||
GuiControl, Disable, % "Player1_" A_Index
|
||||
gosub ComputerTurn
|
||||
Loop 3
|
||||
GuiControl, Disable, % "Player1_" A_Index
|
||||
gosub ComputerTurn
|
||||
}
|
||||
return
|
||||
;-----------------------------------
|
||||
|
|
@ -34,12 +34,12 @@ Total += Added
|
|||
GuiControl,, T, % "Total : " SubStr("00" Total, -1)
|
||||
if (total >= 21)
|
||||
{
|
||||
MsgBox % "Player 1 Wins"
|
||||
gosub reset
|
||||
return
|
||||
MsgBox % "Player 1 Wins"
|
||||
gosub reset
|
||||
return
|
||||
}
|
||||
Loop 3
|
||||
GuiControl, Disable, % "Player1_" A_Index
|
||||
GuiControl, Disable, % "Player1_" A_Index
|
||||
gosub, ComputerTurn
|
||||
return
|
||||
;-----------------------------------
|
||||
|
|
@ -48,38 +48,38 @@ Gui, Submit, NoHide
|
|||
Sleep 500
|
||||
if RadioE
|
||||
{
|
||||
if (total < 13)
|
||||
RadioC := true
|
||||
else
|
||||
RadioH := true
|
||||
if (total < 13)
|
||||
RadioC := true
|
||||
else
|
||||
RadioH := true
|
||||
}
|
||||
if RadioC
|
||||
{
|
||||
Random, Deal, 1, 3
|
||||
total += Deal
|
||||
Random, Deal, 1, 3
|
||||
total += Deal
|
||||
}
|
||||
if RadioH
|
||||
{
|
||||
for i, v in Winners
|
||||
if (total >= v)
|
||||
continue
|
||||
else
|
||||
{
|
||||
Deal := v - total
|
||||
if Deal > 3
|
||||
Random, Deal, 1, 3
|
||||
total += Deal
|
||||
break
|
||||
}
|
||||
for i, v in Winners
|
||||
if (total >= v)
|
||||
continue
|
||||
else
|
||||
{
|
||||
Deal := v - total
|
||||
if Deal > 3
|
||||
Random, Deal, 1, 3
|
||||
total += Deal
|
||||
break
|
||||
}
|
||||
}
|
||||
GuiControl,, T, % "Total : " SubStr("00" Total, -1)
|
||||
GuiControl,, Computer, % "Computer Dealt " Deal
|
||||
if (total=21)
|
||||
{
|
||||
MsgBox Computer Wins
|
||||
gosub, reset
|
||||
MsgBox Computer Wins
|
||||
gosub, reset
|
||||
}
|
||||
else
|
||||
Loop 3
|
||||
GuiControl, Enable, % "Player1_" A_Index
|
||||
Loop 3
|
||||
GuiControl, Enable, % "Player1_" A_Index
|
||||
return
|
||||
|
|
|
|||
|
|
@ -8,81 +8,81 @@ const target: int = 21
|
|||
|
||||
# -1 is returned to request quit
|
||||
func get_player_choice(total: int) -> int:
|
||||
while true:
|
||||
printraw("Player's choice: ")
|
||||
var input: String = OS.read_string_from_stdin().strip_edges()
|
||||
while true:
|
||||
printraw("Player's choice: ")
|
||||
var input: String = OS.read_string_from_stdin().strip_edges()
|
||||
|
||||
if input == "quit":
|
||||
return -1
|
||||
if input == "quit":
|
||||
return -1
|
||||
|
||||
if not input.is_valid_int():
|
||||
print("Please input an integer.")
|
||||
continue
|
||||
if not input.is_valid_int():
|
||||
print("Please input an integer.")
|
||||
continue
|
||||
|
||||
var input_int := int(input)
|
||||
if input_int < 1 or input_int > 3:
|
||||
print("Please pick a number from 1 to 3")
|
||||
continue
|
||||
var input_int := int(input)
|
||||
if input_int < 1 or input_int > 3:
|
||||
print("Please pick a number from 1 to 3")
|
||||
continue
|
||||
|
||||
if input_int + total > target:
|
||||
print("Please do not exceed a total of %d" % target)
|
||||
continue
|
||||
if input_int + total > target:
|
||||
print("Please do not exceed a total of %d" % target)
|
||||
continue
|
||||
|
||||
return input_int
|
||||
return input_int
|
||||
|
||||
# This is required since Godot does not detect the unreachable code path
|
||||
OS.crash("unreachable")
|
||||
return 0
|
||||
# This is required since Godot does not detect the unreachable code path
|
||||
OS.crash("unreachable")
|
||||
return 0
|
||||
|
||||
|
||||
func get_computer_choice(total: int) -> int:
|
||||
# This can be shortened using max() if you do not have type checking OCD
|
||||
var remaining: int = target - total
|
||||
return randi_range(1, 3 if remaining > 3 else remaining)
|
||||
# This can be shortened using max() if you do not have type checking OCD
|
||||
var remaining: int = target - total
|
||||
return randi_range(1, 3 if remaining > 3 else remaining)
|
||||
|
||||
|
||||
func play() -> void:
|
||||
print("""\
|
||||
print("""\
|
||||
Welcome to the 21 game.
|
||||
Type quit to exit.""")
|
||||
var total: int = 0
|
||||
var player: Player
|
||||
match randi_range(1, 2):
|
||||
1:
|
||||
player = Player.Human
|
||||
print("You will go first.")
|
||||
2:
|
||||
player = Player.Computer
|
||||
print("The computer will go first.")
|
||||
var total: int = 0
|
||||
var player: Player
|
||||
match randi_range(1, 2):
|
||||
1:
|
||||
player = Player.Human
|
||||
print("You will go first.")
|
||||
2:
|
||||
player = Player.Computer
|
||||
print("The computer will go first.")
|
||||
|
||||
while true:
|
||||
print("\nThe total is %d" % total)
|
||||
while true:
|
||||
print("\nThe total is %d" % total)
|
||||
|
||||
var choice: int
|
||||
match player:
|
||||
Player.Human:
|
||||
choice = get_player_choice(total)
|
||||
if choice == -1:
|
||||
return
|
||||
Player.Computer:
|
||||
choice = get_computer_choice(total)
|
||||
print("The computer plays %d" % choice)
|
||||
assert(1 <= choice and choice <= 3)
|
||||
var choice: int
|
||||
match player:
|
||||
Player.Human:
|
||||
choice = get_player_choice(total)
|
||||
if choice == -1:
|
||||
return
|
||||
Player.Computer:
|
||||
choice = get_computer_choice(total)
|
||||
print("The computer plays %d" % choice)
|
||||
assert(1 <= choice and choice <= 3)
|
||||
|
||||
total += choice
|
||||
if total == target:
|
||||
match player:
|
||||
Player.Human: print("You win!")
|
||||
Player.Computer: print("The computer won, you lose.")
|
||||
return
|
||||
assert(total < target)
|
||||
total += choice
|
||||
if total == target:
|
||||
match player:
|
||||
Player.Human: print("You win!")
|
||||
Player.Computer: print("The computer won, you lose.")
|
||||
return
|
||||
assert(total < target)
|
||||
|
||||
match player:
|
||||
Player.Human: player = Player.Computer
|
||||
Player.Computer: player = Player.Human
|
||||
match player:
|
||||
Player.Human: player = Player.Computer
|
||||
Player.Computer: player = Player.Human
|
||||
|
||||
|
||||
func _process(_delta: float) -> bool:
|
||||
randomize()
|
||||
play()
|
||||
return true
|
||||
randomize()
|
||||
play()
|
||||
return true
|
||||
|
|
|
|||
|
|
@ -1,62 +1,62 @@
|
|||
from random import randint
|
||||
def start():
|
||||
game_count=0
|
||||
print("Enter q to quit at any time.\nThe computer will choose first.\nRunning total is now {}".format(game_count))
|
||||
roundno=1
|
||||
while game_count<21:
|
||||
print("\nROUND {}: \n".format(roundno))
|
||||
t = select_count(game_count)
|
||||
game_count = game_count+t
|
||||
print("Running total is now {}\n".format(game_count))
|
||||
if game_count>=21:
|
||||
print("So, commiserations, the computer has won!")
|
||||
return 0
|
||||
t = request_count()
|
||||
if not t:
|
||||
print('OK,quitting the game')
|
||||
return -1
|
||||
game_count = game_count+t
|
||||
print("Running total is now {}\n".format(game_count))
|
||||
if game_count>=21:
|
||||
print("So, congratulations, you've won!")
|
||||
return 1
|
||||
roundno+=1
|
||||
game_count=0
|
||||
print("Enter q to quit at any time.\nThe computer will choose first.\nRunning total is now {}".format(game_count))
|
||||
roundno=1
|
||||
while game_count<21:
|
||||
print("\nROUND {}: \n".format(roundno))
|
||||
t = select_count(game_count)
|
||||
game_count = game_count+t
|
||||
print("Running total is now {}\n".format(game_count))
|
||||
if game_count>=21:
|
||||
print("So, commiserations, the computer has won!")
|
||||
return 0
|
||||
t = request_count()
|
||||
if not t:
|
||||
print('OK,quitting the game')
|
||||
return -1
|
||||
game_count = game_count+t
|
||||
print("Running total is now {}\n".format(game_count))
|
||||
if game_count>=21:
|
||||
print("So, congratulations, you've won!")
|
||||
return 1
|
||||
roundno+=1
|
||||
|
||||
def select_count(game_count):
|
||||
'''selects a random number if the game_count is less than 18. otherwise chooses the winning number'''
|
||||
if game_count<18:
|
||||
t= randint(1,3)
|
||||
else:
|
||||
t = 21-game_count
|
||||
print("The computer chooses {}".format(t))
|
||||
return t
|
||||
'''selects a random number if the game_count is less than 18. otherwise chooses the winning number'''
|
||||
if game_count<18:
|
||||
t= randint(1,3)
|
||||
else:
|
||||
t = 21-game_count
|
||||
print("The computer chooses {}".format(t))
|
||||
return t
|
||||
|
||||
def request_count():
|
||||
'''request user input between 1,2 and 3. It will continue till either quit(q) or one of those numbers is requested.'''
|
||||
t=""
|
||||
while True:
|
||||
try:
|
||||
t = raw_input('Your choice 1 to 3 :')
|
||||
if int(t) in [1,2,3]:
|
||||
return int(t)
|
||||
else:
|
||||
print("Out of range, try again")
|
||||
except:
|
||||
if t=="q":
|
||||
return None
|
||||
else:
|
||||
print("Invalid Entry, try again")
|
||||
'''request user input between 1,2 and 3. It will continue till either quit(q) or one of those numbers is requested.'''
|
||||
t=""
|
||||
while True:
|
||||
try:
|
||||
t = raw_input('Your choice 1 to 3 :')
|
||||
if int(t) in [1,2,3]:
|
||||
return int(t)
|
||||
else:
|
||||
print("Out of range, try again")
|
||||
except:
|
||||
if t=="q":
|
||||
return None
|
||||
else:
|
||||
print("Invalid Entry, try again")
|
||||
|
||||
c=0
|
||||
m=0
|
||||
r=True
|
||||
while r:
|
||||
o = start()
|
||||
if o==-1:
|
||||
break
|
||||
else:
|
||||
c+=1 if o==0 else 0
|
||||
m+=1 if o==1 else 0
|
||||
print("Computer wins {0} game, human wins {1} games".format(c,m))
|
||||
t = raw_input("Another game?(press y to continue):")
|
||||
r = (t=="y")
|
||||
o = start()
|
||||
if o==-1:
|
||||
break
|
||||
else:
|
||||
c+=1 if o==0 else 0
|
||||
m+=1 if o==1 else 0
|
||||
print("Computer wins {0} game, human wins {1} games".format(c,m))
|
||||
t = raw_input("Another game?(press y to continue):")
|
||||
r = (t=="y")
|
||||
|
|
|
|||
|
|
@ -100,9 +100,9 @@ func choose(ch,ym)
|
|||
ok
|
||||
|
||||
func msgBox(text) {
|
||||
m = new qMessageBox(win1) {
|
||||
setWindowTitle("21 Game")
|
||||
setText(text)
|
||||
show()
|
||||
}
|
||||
m = new qMessageBox(win1) {
|
||||
setWindowTitle("21 Game")
|
||||
setText(text)
|
||||
show()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue