-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch.go
853 lines (810 loc) · 19.6 KB
/
search.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
// Package ghess is a chess engine. This file concerns the Search
// and keeps a tally of board tension.
package ghess
import (
"bytes"
"strconv"
)
// SearchValid finds two arrays, of all valid possible
// destinations and origins. These are int coordinates
// which point to the index of the byte slice Board.board
func (b *Board) SearchValidSlowly() ([]int, []int) {
movers := make([]int, 0, 16)
targets := make([]int, 0, 64)
origs := make([]int, 0, 16)
dests := make([]int, 0, 64)
// Find and sort pieces:
for idx, val := range b.board {
// Only look for 64 squares
/*if idx%10 == 0 || (idx+1)%10 == 0 ||
idx > 88 || idx < 11 {
continue
}*/
if val != ' ' && b.toMove == "w" && b.isUpper(idx) && val != '.' {
movers = append(movers, idx)
} else if val != ' ' && b.toMove == "b" &&
!b.isUpper(idx) && val != '.' {
movers = append(movers, idx)
} else if val != ' ' {
targets = append(targets, idx)
}
}
// Add Castle (edge squares to targets
if b.toMove == "w" {
if b.castle[1] == 'Q' {
targets = append(targets, 18)
}
if b.castle[0] == 'K' {
targets = append(targets, 11)
}
}
if b.toMove == "b" {
if b.castle[3] == 'q' {
targets = append(targets, 88)
}
if b.castle[2] == 'k' {
targets = append(targets, 81)
}
}
// Check for Valid attacks
for _, idx := range movers {
for _, target := range targets {
var e error
var isCheck bool
possible := CopyBoard(b)
e = possible.Move(idx, target)
if e == nil {
// Can't move into check
isCheck = possible.isOpponentInCheck()
}
if e == nil && !isCheck {
origs = append(origs, idx)
dests = append(dests, target)
}
}
}
return origs, dests
}
// SearchValid finds two arrays, of all valid possible
// destinations and origins. These are int coordinates
// which point to the index of the byte slice Board.board
func (b *Board) SearchValid() ([]int, []int) {
movers := make([]int, 0, 16)
origs := make([]int, 0, 16)
dests := make([]int, 0, 64)
// Find and sort pieces:
for idx, val := range b.board {
// Only look for 64 squares
if val != ' ' && b.toMove == "w" && b.isUpper(idx) && val != '.' {
movers = append(movers, idx)
} else if val != ' ' && b.toMove == "b" &&
!b.isUpper(idx) && val != '.' {
movers = append(movers, idx)
}
}
for _, idx := range movers {
switch b.board[idx] {
case 'p', 'P':
o, d := b.searchPawn(idx)
origs = append(origs, o...)
dests = append(dests, d...)
case 'n', 'N':
o, d := b.searchKnight(idx)
origs = append(origs, o...)
dests = append(dests, d...)
case 'b', 'B':
o, d := b.searchBishop(idx)
origs = append(origs, o...)
dests = append(dests, d...)
case 'r', 'R':
o, d := b.searchRook(idx)
origs = append(origs, o...)
dests = append(dests, d...)
case 'q', 'Q':
o, d := b.searchQueen(idx)
origs = append(origs, o...)
dests = append(dests, d...)
case 'k', 'K':
o, d := b.searchKing(idx)
origs = append(origs, o...)
dests = append(dests, d...)
}
}
return origs, dests
}
// checkForCheck avoids validating the move, but simply
// checks if a new position would put the opponent in check
// (which is illegal)
func (b *Board) searchOk(o, d int) bool {
possible := CopyBoard(b)
possible.updateBoard(o, d, b.board[o], false, false)
if possible.isOpponentInCheck() {
return false
}
return true
}
func (b *Board) searchPawn(orig int) ([]int, []int) {
isWhite := b.isUpper(orig)
origs := make([]int, 0)
dests := make([]int, 0)
var possibilities [4]int
// TODO: Check for Empassant
if isWhite {
possibilities[0] = orig + 10
possibilities[1] = orig + 20
possibilities[2] = orig + 11
possibilities[3] = orig + 9
} else {
possibilities[0] = orig - 10
possibilities[1] = orig - 20
possibilities[2] = orig - 11
possibilities[3] = orig - 9
}
for idx, possibility := range possibilities {
if possibility > 89 || possibility < 11 {
continue
}
switch b.board[possibility] {
case ' ':
continue
case '.':
if idx == 0 {
if b.searchOk(orig, possibility) {
origs = append(origs, orig)
dests = append(dests, possibility)
}
} else if idx == 1 && (orig < 29 || orig > 69) {
if isWhite {
if b.board[orig+10] != '.' {
continue
}
} else {
if b.board[orig-10] != '.' {
continue
}
}
if b.searchOk(orig, possibility) {
origs = append(origs, orig)
dests = append(dests, possibility)
}
}
default: // if it's a piece
if (idx == 2 || idx == 3) &&
isWhite && !b.isUpper(possibility) {
if b.searchOk(orig, possibility) {
origs = append(origs, orig)
dests = append(dests, possibility)
}
} else if (idx == 2 || idx == 3) &&
!isWhite && b.isUpper(possibility) {
if b.searchOk(orig, possibility) {
origs = append(origs, orig)
dests = append(dests, possibility)
}
}
}
}
return origs, dests
}
func (b *Board) searchKnight(orig int) ([]int, []int) {
isWhite := b.isUpper(orig)
origs := make([]int, 0)
dests := make([]int, 0)
var possibilities [8]int
possibilities[0], possibilities[1],
possibilities[2], possibilities[3],
possibilities[4], possibilities[5],
possibilities[6], possibilities[7] = orig+21,
orig+19, orig+12, orig+8, orig-8,
orig-12, orig-19, orig-21
PossLoop:
for _, possibility := range possibilities {
if possibility > 89 || possibility < 11 {
continue PossLoop
}
switch b.board[possibility] {
case ' ':
continue PossLoop
case '.':
if b.searchOk(orig, possibility) {
origs = append(origs, orig)
dests = append(dests, possibility)
}
default: // if it's a piece
if isWhite && !b.isUpper(possibility) {
if b.searchOk(orig, possibility) {
origs = append(origs, orig)
dests = append(dests, possibility)
}
} else if !isWhite && b.isUpper(possibility) {
if b.searchOk(orig, possibility) {
origs = append(origs, orig)
dests = append(dests, possibility)
}
}
}
}
return origs, dests
}
func (b *Board) searchBishop(orig int) ([]int, []int) {
isWhite := b.isUpper(orig)
origs := make([]int, 0)
dests := make([]int, 0)
// Not by possibility.. but rather check diagnols..
a1h8Loop:
for target := orig + 9; target < 89; target = target + 9 {
// Should stop when off the board
switch b.board[target] {
case ' ':
break a1h8Loop
case '.':
if b.searchOk(orig, target) {
origs = append(origs, orig)
dests = append(dests, target)
}
case 'p', 'n', 'b', 'r', 'q', 'k':
if isWhite {
if b.searchOk(orig, target) {
origs = append(origs, orig)
dests = append(dests, target)
}
}
break a1h8Loop
case 'P', 'N', 'B', 'R', 'Q', 'K':
if !isWhite {
if b.searchOk(orig, target) {
origs = append(origs, orig)
dests = append(dests, target)
}
}
break a1h8Loop
}
}
h8a1Loop:
for target := orig - 9; target > 10; target = target - 9 {
// Should stop when off the board
switch b.board[target] {
case ' ':
break h8a1Loop
case '.':
if b.searchOk(orig, target) {
origs = append(origs, orig)
dests = append(dests, target)
}
case 'p', 'n', 'b', 'r', 'q', 'k':
if isWhite {
if b.searchOk(orig, target) {
origs = append(origs, orig)
dests = append(dests, target)
}
}
break h8a1Loop
case 'P', 'N', 'B', 'R', 'Q', 'K':
if !isWhite {
if b.searchOk(orig, target) {
origs = append(origs, orig)
dests = append(dests, target)
}
}
break h8a1Loop
}
}
h1a8Loop:
for target := orig + 11; target < 89; target = target + 11 {
// Should stop when off the board
switch b.board[target] {
case ' ':
break h1a8Loop
case '.':
if b.searchOk(orig, target) {
origs = append(origs, orig)
dests = append(dests, target)
}
case 'p', 'n', 'b', 'r', 'q', 'k':
if isWhite {
if b.searchOk(orig, target) {
origs = append(origs, orig)
dests = append(dests, target)
}
}
break h1a8Loop
case 'P', 'N', 'B', 'R', 'Q', 'K':
if !isWhite {
if b.searchOk(orig, target) {
origs = append(origs, orig)
dests = append(dests, target)
}
}
break h1a8Loop
}
}
a8h1Loop:
for target := orig - 11; target > 10; target = target - 11 {
// Should stop when off the board
switch b.board[target] {
case ' ':
break a8h1Loop
case '.':
if b.searchOk(orig, target) {
origs = append(origs, orig)
dests = append(dests, target)
}
case 'p', 'n', 'b', 'r', 'q', 'k':
if isWhite {
if b.searchOk(orig, target) {
origs = append(origs, orig)
dests = append(dests, target)
}
}
break a8h1Loop
case 'P', 'N', 'B', 'R', 'Q', 'K':
if !isWhite {
if b.searchOk(orig, target) {
origs = append(origs, orig)
dests = append(dests, target)
}
}
break a8h1Loop
}
}
return origs, dests
}
func (b *Board) searchRook(orig int) ([]int, []int) {
isWhite := b.isUpper(orig)
origs := make([]int, 0)
dests := make([]int, 0)
RightLoop:
for i := orig + 1; !((i+1)%10 == 0); i = i + 1 {
switch b.board[i] {
case ' ':
break RightLoop
case '.':
if b.searchOk(orig, i) {
origs = append(origs, orig)
dests = append(dests, i)
}
case 'p', 'n', 'b', 'r', 'q', 'k':
if isWhite {
if b.searchOk(orig, i) {
origs = append(origs, orig)
dests = append(dests, i)
}
}
break RightLoop
case 'P', 'N', 'B', 'R', 'Q', 'K':
if !isWhite {
if b.searchOk(orig, i) {
origs = append(origs, orig)
dests = append(dests, i)
}
}
break RightLoop
}
}
LeftLoop:
for i := orig - 1; !(i%10 == 0); i = i - 1 {
switch b.board[i] {
case ' ':
break LeftLoop
case '.':
if b.searchOk(orig, i) {
origs = append(origs, orig)
dests = append(dests, i)
}
case 'p', 'n', 'b', 'r', 'q', 'k':
if isWhite {
if b.searchOk(orig, i) {
origs = append(origs, orig)
dests = append(dests, i)
}
}
break LeftLoop
case 'P', 'N', 'B', 'R', 'Q', 'K':
if !isWhite {
if b.searchOk(orig, i) {
origs = append(origs, orig)
dests = append(dests, i)
}
}
break LeftLoop
}
}
UpVerLoop:
for i := orig + 10; i < 88; i = i + 10 {
switch b.board[i] {
case ' ':
break UpVerLoop
case '.':
if b.searchOk(orig, i) {
origs = append(origs, orig)
dests = append(dests, i)
}
case 'p', 'n', 'b', 'r', 'q', 'k':
if isWhite {
if b.searchOk(orig, i) {
origs = append(origs, orig)
dests = append(dests, i)
}
}
break UpVerLoop
case 'P', 'N', 'B', 'R', 'Q', 'K':
if !isWhite {
if b.searchOk(orig, i) {
origs = append(origs, orig)
dests = append(dests, i)
}
}
break UpVerLoop
}
}
DownVerLoop:
for i := orig - 10; i > 10; i = i - 10 {
// Should stop when off the board
switch b.board[i] {
case ' ':
break DownVerLoop
case '.':
if b.searchOk(orig, i) {
origs = append(origs, orig)
dests = append(dests, i)
}
case 'p', 'n', 'b', 'r', 'q', 'k':
if isWhite {
if b.searchOk(orig, i) {
origs = append(origs, orig)
dests = append(dests, i)
}
}
break DownVerLoop
case 'P', 'N', 'B', 'R', 'Q', 'K':
if !isWhite {
if b.searchOk(orig, i) {
origs = append(origs, orig)
dests = append(dests, i)
}
}
break DownVerLoop
}
}
return origs, dests
}
func (b *Board) searchQueen(orig int) ([]int, []int) {
//isWhite := b.isUpper(orig)
origs := make([]int, 0)
dests := make([]int, 0)
o, d := b.searchBishop(orig)
origs = append(origs, o...)
dests = append(dests, d...)
o, d = b.searchRook(orig)
origs = append(origs, o...)
dests = append(dests, d...)
return origs, dests
}
func (b *Board) searchKing(orig int) ([]int, []int) {
isWhite := b.isUpper(orig)
origs := make([]int, 0)
dests := make([]int, 0)
var possibilities [8]int
possibilities[0], possibilities[1],
possibilities[2], possibilities[3],
possibilities[4], possibilities[5],
possibilities[6], possibilities[7] = orig+11,
orig+9, orig+10, orig+1, orig-11,
orig-10, orig-9, orig-1
// Check kings close
for _, possibility := range possibilities {
switch b.board[possibility] {
case ' ':
continue
case '.':
if b.searchOk(orig, possibility) {
origs = append(origs, orig)
dests = append(dests, possibility)
}
default: // if it's a piece
if isWhite && !b.isUpper(possibility) {
if b.searchOk(orig, possibility) {
origs = append(origs, orig)
dests = append(dests, possibility)
}
} else if !isWhite && b.isUpper(possibility) {
if b.searchOk(orig, possibility) {
origs = append(origs, orig)
dests = append(dests, possibility)
}
}
}
}
if isWhite {
if b.castle[1] == 'Q' && b.board[orig+1] == '.' {
possible := CopyBoard(b)
e := possible.Move(orig, 18)
if e == nil {
origs = append(origs, orig)
dests = append(dests, 18)
}
}
if b.castle[0] == 'K' && b.board[orig-1] == '.' {
possible := CopyBoard(b)
e := possible.Move(orig, 11)
if e == nil {
origs = append(origs, orig)
dests = append(dests, 11)
}
}
} else {
if b.castle[3] == 'q' && b.board[orig+1] == '.' {
possible := CopyBoard(b)
e := possible.Move(orig, 88)
if e == nil {
origs = append(origs, orig)
dests = append(dests, 88)
}
}
if b.castle[2] == 'k' && b.board[orig-1] == '.' {
possible := CopyBoard(b)
e := possible.Move(orig, 81)
if e == nil {
origs = append(origs, orig)
dests = append(dests, 81)
}
}
}
return origs, dests
}
// Tension returns a map of which squares are attacked
// by which side. Negative for black Positive for white.
// TODO: For now it wont take not moving out of check into account?
// TODO: Empassant isn't counted in tension
func (b *Board) Tension() map[int]int {
tension := make(map[int]int)
whites := make([]int, 0, 16) // white movers black targets
blacks := make([]int, 0, 16) // black movers white targets
// Todo, do I need blanks?
blanks := make([]int, 0, 63) // everyone's targets
// Find and sort pieces:
for idx, val := range b.board {
// Only look for 64 squares
if idx%10 == 0 || (idx+1)%10 == 0 || idx > 88 || idx < 11 {
continue
}
// TODO:
// This is why Castle search return in valid doesn't work
if b.isUpper(idx) && val != '.' {
whites = append(whites, idx)
} else if !b.isUpper(idx) && val != '.' {
blacks = append(blacks, idx)
} else {
blanks = append(blanks, idx)
}
}
// Increment For Squares white is attacking
for _, idx := range whites {
whiteTargets := append(blanks, blacks...)
whiteTargets = append(whiteTargets, whites...)
p := bytes.ToUpper(b.board[idx : idx+1])[0]
// Check for Pawn attacks, cause they're weird:
if p == 'P' {
if (idx+9)%10 != 0 {
tension[idx+9]++
}
if (idx+11)%10 != 0 {
tension[idx+11]++
}
}
WhiteValidator:
for _, target := range whiteTargets {
// TODO: Check for Castling
var e error
switch p {
case 'P':
continue WhiteValidator
case 'N':
e = b.validKnight(idx, target)
case 'B':
e = b.validBishop(idx, target)
case 'R':
e = b.validRook(idx, target)
case 'Q':
e = b.validQueen(idx, target)
case 'K':
e = b.validKing(idx, target, false)
// Don't check for castling? Cause that's not pressure
}
if e == nil {
// Is valid
tension[target]++
}
}
}
//Decrement for Squares black is attacking
for _, idx := range blacks {
blackTargets := append(blanks, whites...)
blackTargets = append(blackTargets, blacks...)
p := bytes.ToUpper(b.board[idx : idx+1])[0]
// Check for Pawn attacks, cause they're weird:
if p == 'P' {
if (idx-9)%10 != 0 {
tension[idx-9]--
}
if (idx-11)%10 != 0 {
tension[idx-11]--
}
}
BlackValidator:
for _, target := range blackTargets {
// TODO: Check for Castling
var e error
switch p {
case 'P': // Cause pawns are weird
continue BlackValidator
case 'N':
e = b.validKnight(idx, target)
case 'B':
e = b.validBishop(idx, target)
case 'R':
e = b.validRook(idx, target)
case 'Q':
e = b.validQueen(idx, target)
case 'K':
e = b.validKing(idx, target, false)
//e = b.validKing(idx, target, true)
//fmt.Println("King")
}
if e == nil {
tension[target]--
}
}
}
return tension
}
func (b *Board) TensionSum() int {
tension := b.Tension()
var sum int
for _, v := range tension {
sum += v
}
return sum
}
// StringTension Prints the board with numbers according to the
// amount of attacks by either black or white, negative for black
// and positive for white.
func (b *Board) StringTension() string {
tension := b.Tension()
var nums [8]byte // somehow print these?
nums[0], nums[1], nums[2], nums[3], nums[4], nums[5], nums[6], nums[7] = '1', '2', '3', '4', '5', '6', '7', '8'
//p := b.pieces
var printBoard string
j := 7
for i := 89; i > 10; i-- {
if i%10 == 0 {
printBoard += string(nums[j]) + ": " + "\n"
j--
continue
} else if (i+1)%10 == 0 {
continue
}
if tension[i] == 0 {
printBoard += "| 0|"
} else {
if tension[i] < 0 {
printBoard += "|" + strconv.Itoa(tension[i]) + "|"
} else {
printBoard += "| " + strconv.Itoa(tension[i]) + "|"
}
}
}
printBoard += string(nums[j]) + ": " + "\n"
printBoard += ": a:: b:: c:: d:: e:: f:: g:: h:\n"
return printBoard
}
// Deprecated:
func (b *Board) SearchValidSlow() ([]int, []int) {
movers := make([]int, 0, 16)
targets := make([]int, 0, 64)
origs := make([]int, 0, 16)
dests := make([]int, 0, 64)
validO := make([]int, 0, 16)
validD := make([]int, 0, 64)
isWhite := b.toMove == "w"
var king int
// Find and sort pieces:
for idx, val := range b.board {
// Only look for 64 squares
if idx%10 == 0 || (idx+1)%10 == 0 || idx > 88 || idx < 11 {
continue
}
if val == 'K' || val == 'k' {
if isWhite && val == 'K' {
king = idx
} else if !isWhite && val == 'k' {
king = idx
}
}
if b.toMove == "w" && b.isUpper(idx) && val != '.' {
movers = append(movers, idx)
} else if b.toMove == "b" && !b.isUpper(idx) && val != '.' {
movers = append(movers, idx)
} else {
targets = append(targets, idx)
}
}
// Add Castle to targets
if b.toMove == "w" {
if b.castle[1] == 'Q' {
targets = append(targets, 18)
}
if b.castle[0] == 'K' {
targets = append(targets, 11)
}
}
if b.toMove == "b" {
if b.castle[3] == 'q' {
targets = append(targets, 88)
}
if b.castle[2] == 'k' {
targets = append(targets, 81)
}
}
// Check for Valid attacks
for _, idx := range movers {
p := bytes.ToUpper(b.board[idx : idx+1])[0]
for _, target := range targets {
var e error
switch p {
case 'P':
// why am I not looking at pawns?
//e = b.validPawn(idx, target)
case 'N':
e = b.validKnight(idx, target)
case 'B':
e = b.validBishop(idx, target)
case 'R':
e = b.validRook(idx, target)
case 'Q':
e = b.validQueen(idx, target)
case 'K':
e = b.validKing(idx, target, false)
if e == nil {
origs = append(origs, idx)
dests = append(dests, target)
continue
}
err := b.validKing(idx, target, true)
if err == nil {
origs = append(origs, idx)
dests = append(dests, target)
continue
}
}
if e == nil {
origs = append(origs, idx)
dests = append(dests, target)
}
}
}
// Check if it moves into Check
//for i := 0; i < len(origs); i++ {
for i, v := range origs {
var k int
// Check if King is the piece moved
if b.board[v] == 'k' || b.board[v] == 'K' {
k = dests[i]
} else {
k = king
}
// Copy board to "make move" as the move must be made
// in order to test for check
possible := CopyBoard(b)
err := possible.Move(origs[i], dests[i])
isCheck := possible.isInCheck(k)
//if dests[i] == 75 && isCheck {
//fmt.Println(origs[i], "What?", king)
//}
if err == nil && !isCheck {
validO = append(validO, origs[i])
validD = append(validD, dests[i])
}
}
return validO, validD
}