Anonymous user
Rock-paper-scissors: Difference between revisions
m
→{{header|Lua}}: Spot of refactoring
(→{{header|Rust}}: add Rust solution) |
m (→{{header|Lua}}: Spot of refactoring) |
||
Line 3,006:
=={{header|Lua}}==
<lang Lua>function cpuMove()
if totalChance == 0 then -- First game, unweighted random
▲ local totalChance = playerRecord.R + playerRecord.P + playerRecord.S
▲ local choice = math.random(1, 3)
▲ end
▲ if choice <= playerRecord.R then return "P" end
▲ if choice <= playerRecord.R + playerRecord.P then return "S" end
▲ return "R"
end
function playerMove() -- Get user input for choice of 'weapon'
end
function checkWinner (c, p)
if c == p then
elseif (c == "R" and p == "P") or▼
end
-- Main procedure
math.randomseed(os.time())
▲score = {player = 0, cpu = 0, draws = 0} -- Start of main procedure
▲playerRecord = {R = 0, P = 0, S = 0}
local playerChoice, cpuChoice
repeat
until
Session in which I chose nothing but rock:
<pre>
|