@@ -57,16 +57,17 @@ func EnableBoxes() bool {
5757 }
5858 for _ , box := range boxes {
5959 box .disable = false
60+ box .WinStyle (false )
6061 }
6162 return true
6263}
6364
64- func ColorBoxes (boxes ... * BoxHolder ) bool {
65+ func ColorBoxes (boxes [] * BoxHolder ) bool {
6566 if boxes == nil {
6667 return false
6768 }
6869 for _ , box := range boxes {
69- box .ChangeStyle ( )
70+ box .WinStyle ( true )
7071 }
7172 return true
7273}
@@ -75,7 +76,7 @@ func ColorBoxes(boxes ...*BoxHolder) bool {
7576// each box has its own inputevents too.
7677// The function returns if the end of the game reached and the winner.
7778
78- func IsTerminal () (bool , int ) {
79+ func IsTerminal () (bool , int , [] * BoxHolder ) {
7980 winPatterns := [8 ][3 ]int {
8081 {0 , 1 , 2 },
8182 {3 , 4 , 5 },
@@ -91,28 +92,33 @@ func IsTerminal() (bool, int) {
9192 if boxes [pattern [0 ]].content != ' ' &&
9293 boxes [pattern [0 ]].content == boxes [pattern [1 ]].content &&
9394 boxes [pattern [1 ]].content == boxes [pattern [2 ]].content {
94- ColorBoxes (boxes [pattern [0 ]], boxes [pattern [1 ]], boxes [pattern [2 ]])
95- // check if O
95+
96+ // winning boxes
97+ winners := []* BoxHolder {
98+ boxes [pattern [0 ]],
99+ boxes [pattern [1 ]],
100+ boxes [pattern [2 ]],
101+ }
102+
96103 if boxes [pattern [0 ]].content == 'O' {
97- return true , 1
104+ return true , 1 , winners
98105 }
99- // check if X
100- return true , - 1
106+ return true , - 1 , winners
101107 }
102108 }
103109
104110 // check if there are empty boxes
105111 for i := range boxes {
106112 if boxes [i ].content == ' ' {
107- return false , 0
113+ return false , 0 , nil
108114 }
109115 }
110116 // no winners - End of the game
111- return true , 0
117+ return true , 0 , nil
112118}
113119
114120func Minimax (isMaximizing bool ) int {
115- terminal , score := IsTerminal ()
121+ terminal , score , _ := IsTerminal ()
116122 if terminal {
117123 return score
118124 }
0 commit comments