-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.spx
138 lines (127 loc) · 2.79 KB
/
main.spx
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
var (
Chess Chess
Button4 Button4
CurrentChess CurrentChess
Cat1 Cat1
Undoer Undoer
undoIdList List
undoOpList List
undoParamList List
gameState List
restoreList List
visitList List
col int
currentCol int
_White int
_Eating int
_Black int
pos int
ret int
mayBeEaten int
currentPlayer int
currentRow int
undoing int
player int
row int
eatNum int
eatenPlayer int
restoreNum int
)
func initConsts() {
_Black = 1
_White = 2
_Eating = 3
}
func calcHitPosition(x float64, y float64) {
col = iround((x + 159) / 17.7)
row = iround((y - 159) / -17.7)
if row < 0 || col < 0 || row > 18 || col > 18 {
ret = 0
} else {
ret = row*19 + col + 1
}
}
func initGameState() {
gameState.delete All
for i := 0; i < 361; i++ {
gameState.append 0
}
}
func checkEat() {
eatNum = 0
eatenPlayer = 3 - currentPlayer
checkEatChess currentRow+1, currentCol, eatenPlayer
checkEatChess currentRow-1, currentCol, eatenPlayer
checkEatChess currentRow, currentCol+1, eatenPlayer
checkEatChess currentRow, currentCol-1, eatenPlayer
restoreRestoreList eatenPlayer
if eatNum == 0 {
eatenPlayer = currentPlayer
checkEatChess currentRow, currentCol, eatenPlayer
restoreRestoreList eatenPlayer
}
if eatNum > 0 {
broadcast "eat chesses", true
}
}
func checkEatChess(row int, col int, expectPlayer int) {
mayBeEaten = 1
confirmChessEatenOrNot row, col, expectPlayer
if mayBeEaten == 1 {
eatNum += visitList.len
} else {
pos = 1
for i := visitList.len; i > 0; i-- {
restoreList.append visitList.at(pos-1)
pos++
}
}
visitList.delete All
}
func confirmChessEatenOrNot(row int, col int, expectPlayer int) {
if mayBeEaten == 1 && !(row < 0 || col < 0 || row > 18 || col > 18) {
pos = row*19 + (col + 1)
player = gameState.at(pos - 1).int
if player == expectPlayer {
visitList.append pos
gameState.set pos-1, _Eating
confirmChessEatenOrNot row+1, col, expectPlayer
confirmChessEatenOrNot row-1, col, expectPlayer
confirmChessEatenOrNot row, col+1, expectPlayer
confirmChessEatenOrNot row, col-1, expectPlayer
} else {
if player == 0 {
mayBeEaten = 0
}
}
}
}
func restoreRestoreList(expectPlayer int) {
restoreNum = restoreList.len
pos = 1
for i := restoreList.len; i > 0; i-- {
gameState.set restoreList.at(pos-1).int-1, expectPlayer
pos++
}
restoreList.delete All
}
onStart => {
initConsts
initGameState
currentPlayer = _Black
}
onClick => {
calcHitPosition mouseX, mouseY
if ret > 0 && gameState.at(ret-1).int == 0 {
currentCol = col
currentRow = row
broadcast "try put chess"
}
}
onMsg "confirm to put chess", => {
Chess.clone
}
onMsg "put chess done", => {
checkEat
currentPlayer = 3 - currentPlayer
}