-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgame.lua
48 lines (38 loc) · 867 Bytes
/
game.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
require('backgammon')
--[[
Backgammon game simulation.
]]
player1 = 1
player2 = 2
board = createBoard()
local debugMode = false
while true do
print("PLAYER 1 is playing...")
local dice = rollDice()
local move = play(player1, board, dice, selectBestMove)
if move == nil then
print("Can not play, waiting...")
else
board = move.board
prettyPrintMove(move)
if board.bearingOffCheckers[player1] == 15 then
print("PLAYER 1 WINS")
break
end
end
if debugMode then local line = io.read() end
print("PLAYER 2 is playing...")
dice = rollDice()
move = play(player2, board, dice, nil)
if move == nil then
print("Can not play, waiting...")
else
board = move.board
prettyPrintMove(move)
if board.bearingOffCheckers[player2] == 15 then
print("PLAYER 2 WINS")
break
end
end
if debugMode then local line = io.read() end
end