@@ -121,6 +121,83 @@ func formatNodesCount(nodes int64) string {
121121 return fmt .Sprintf ("%.2fM" , float64 (nodes )/ 1000000 )
122122}
123123
124+ func formatBoard (b * Board ) string {
125+ files := " a b c d e f g h"
126+ str := fmt .Sprintf ("%s\n " , files )
127+
128+ lastMoveSquare := Invalid
129+
130+ if len (b .history ) > 0 {
131+ lastMoveSquare = b .history [len (b .history )- 1 ].move .To
132+ }
133+
134+ for rank := int8 (7 ); rank >= 0 ; rank -- {
135+ var s = fmt .Sprintf ("%d " , rank + 1 )
136+ for file := int8 (0 ); file < 8 ; file ++ {
137+ moved := " "
138+ if square (rank , file ) == int8 (lastMoveSquare ) {
139+ moved = "*"
140+ }
141+ s += fmt .Sprintf ("%s%s " , symbol (b .data [square (rank , file )]), moved )
142+ }
143+ if rank == 4 {
144+ color := "white"
145+ if b .sideToMove == Black {
146+ color = "black"
147+ }
148+ s += fmt .Sprintf ("\t (%d) %s's move" , b .fullMoves , color )
149+ }
150+ if rank == 3 {
151+ c := ""
152+ if b .whiteCastle & castleShort != 0 {
153+ c += "K"
154+ }
155+ if b .whiteCastle & castleLong != 0 {
156+ c += "Q"
157+ }
158+ if b .blackCastle & castleShort != 0 {
159+ c += "k"
160+ }
161+ if b .blackCastle & castleLong != 0 {
162+ c += "q"
163+ }
164+ if len (c ) == 0 {
165+ c = "-"
166+ }
167+ s += fmt .Sprintf ("\t Casteling: %s" , c )
168+ }
169+ if rank == 2 {
170+ gen := NewGenerator (b )
171+ if gen .CheckSimple () {
172+ s += fmt .Sprintf ("\t Check!" )
173+ }
174+ }
175+ str += fmt .Sprintf ("%s\n " , s )
176+ }
177+ lastMove := ""
178+ if len (b .history ) > 0 {
179+ lastMove = b .history [len (b .history )- 1 ].move .String ()
180+ }
181+ str += fmt .Sprintf ("%s\t %s\t " , files , lastMove )
182+
183+ switch b .status {
184+ case statusCheck :
185+ str += "Check!"
186+ case statusDraw :
187+ str += "Draw!"
188+ case statusWhiteMates :
189+ str += "Mate! White wins."
190+ case statusBlackMates :
191+ str += "Mate! Black wins."
192+ case statusStaleMate :
193+ str += "Stale mate!"
194+ }
195+
196+ str += "\n "
197+
198+ return str
199+ }
200+
124201func abs (v int8 ) int8 {
125202 if v >= 0 {
126203 return v
0 commit comments