-
Notifications
You must be signed in to change notification settings - Fork 1
/
carcassonne_test.go
116 lines (103 loc) · 3.01 KB
/
carcassonne_test.go
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package go_carcassonne
import (
"testing"
"time"
bg "github.com/quibbble/go-boardgame"
"github.com/stretchr/testify/assert"
)
const (
TeamA = "TeamA"
TeamB = "TeamB"
)
func Test_Carcassonne(t *testing.T) {
carcassonne, err := NewCarcassonne(&bg.BoardGameOptions{
Teams: []string{TeamA, TeamB},
MoreOptions: CarcassonneMoreOptions{
Seed: time.Now().UnixNano(),
},
})
if err != nil {
t.Error(err)
t.FailNow()
}
assert.Equal(t, 1, len(carcassonne.state.board.board), "board missing start tile")
// place all road tile to right of start tile
carcassonne.state.playTiles[carcassonne.state.turn] = newTile(Road, Road, Road, Road, NilStructure, false, false)
carcassonne.state.turn = TeamA
err = carcassonne.Do(&bg.BoardGameAction{
Team: TeamA,
ActionType: ActionPlaceTile,
MoreDetails: PlaceTileActionDetails{
X: 1,
Y: 0,
Tile: TileActionDetails{
Road, Road, Road, Road, NilStructure, false, false,
},
},
})
if err != nil {
t.Error(err)
t.FailNow()
}
assert.Equal(t, 2, len(carcassonne.state.board.board), "board missing last placed tile")
// place token in left B side of farmland
err = carcassonne.Do(&bg.BoardGameAction{
Team: TeamA,
ActionType: ActionPlaceToken,
MoreDetails: PlaceTokenActionDetails{
Pass: false,
X: 1,
Y: 0,
Type: Farmer,
Side: FarmSideLeftB,
},
})
if err != nil {
t.Error(err)
t.FailNow()
}
assert.Equal(t, 1, len(carcassonne.state.boardTokens), "missing placed token")
assert.Equal(t, Farmer, carcassonne.state.boardTokens[0].Type, "incorrect token placed")
assert.Equal(t, TeamB, carcassonne.state.turn, "incorrect team's turn")
// place tile to left of start tile completing a road segment
carcassonne.state.playTiles[carcassonne.state.turn] = newTile(Road, Road, Farm, Road, NilStructure, false, false)
err = carcassonne.Do(&bg.BoardGameAction{
Team: TeamB,
ActionType: ActionPlaceTile,
MoreDetails: PlaceTileActionDetails{
X: -1,
Y: 0,
Tile: TileActionDetails{
Road, Road, Farm, Road, NilStructure, false, false,
},
},
})
if err != nil {
t.Error(err)
t.FailNow()
}
assert.Equal(t, 3, len(carcassonne.state.board.board), "board missing last place tile")
// claim the completed road by placing thief on right side of tile
err = carcassonne.Do(&bg.BoardGameAction{
Team: TeamB,
ActionType: ActionPlaceToken,
MoreDetails: PlaceTokenActionDetails{
Pass: false,
X: -1,
Y: 0,
Type: Thief,
Side: SideRight,
},
})
if err != nil {
t.Error(err)
t.FailNow()
}
assert.Equal(t, 1, len(carcassonne.state.boardTokens))
assert.Equal(t, 3, carcassonne.state.scores[TeamB])
assert.Equal(t, []string{TeamB}, carcassonne.state.board.board[0].Teams[SideLeft])
assert.Equal(t, []string{TeamB}, carcassonne.state.board.board[0].Teams[SideRight])
assert.Equal(t, []string{TeamB}, carcassonne.state.board.board[1].Teams[SideLeft])
assert.Equal(t, []string{TeamB}, carcassonne.state.board.board[2].Teams[SideRight])
assert.Equal(t, TeamA, carcassonne.state.turn)
}