How to resolve the algorithm 21 game step by step in the AutoHotkey programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm 21 game step by step in the AutoHotkey programming language
Table of Contents
Problem Statement
21 is a two player game, the game is played by choosing a number (1, 2, or 3) to be added to the running total. The game is won by the player whose chosen number causes the running total to reach exactly 21. The running total starts at zero. One player will be the computer. Players alternate supplying a number to be added to the running total.
Write a computer program that will:
Let's start with the solution:
Step by Step solution about How to resolve the algorithm 21 game step by step in the AutoHotkey programming language
Source code in the autohotkey programming language
Gui, font, S16
Gui, add, Radio, vRadioC , Cake
Gui, add, Radio, vRadioE x+0 Checked, Easy
Gui, add, Radio, vRadioH x+0, Hard
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, xs vReset gReset, reset
Gui show,, 21 Game
Winners := [1,5,9,13,17,21]
gosub, reset
return
;-----------------------------------
reset:
total := 0
GuiControl,, T, % "Total : " SubStr("00" Total, -1)
GuiControl,, Computer, % "Computer Waiting"
Loop 3
GuiControl, Enable, % "Player1_" A_Index
Random, rnd, 0, 1
if rnd
{
Loop 3
GuiControl, Disable, % "Player1_" A_Index
gosub ComputerTurn
}
return
;-----------------------------------
Total:
Added := SubStr(A_GuiControl, 9,1)
Total += Added
GuiControl,, T, % "Total : " SubStr("00" Total, -1)
if (total >= 21)
{
MsgBox % "Player 1 Wins"
gosub reset
return
}
Loop 3
GuiControl, Disable, % "Player1_" A_Index
gosub, ComputerTurn
return
;-----------------------------------
ComputerTurn:
Gui, Submit, NoHide
Sleep 500
if RadioE
{
if (total < 13)
RadioC := true
else
RadioH := true
}
if RadioC
{
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
}
}
GuiControl,, T, % "Total : " SubStr("00" Total, -1)
GuiControl,, Computer, % "Computer Dealt " Deal
if (total=21)
{
MsgBox Computer Wins
gosub, reset
}
else
Loop 3
GuiControl, Enable, % "Player1_" A_Index
return
You may also check:How to resolve the algorithm Integer comparison step by step in the Mathematica / Wolfram Language programming language
You may also check:How to resolve the algorithm Matrix transposition step by step in the Run BASIC programming language
You may also check:How to resolve the algorithm Non-decimal radices/Input step by step in the Java programming language
You may also check:How to resolve the algorithm Arena storage pool step by step in the zkl programming language
You may also check:How to resolve the algorithm Elementary cellular automaton step by step in the EchoLisp programming language