Last active
December 21, 2016 16:29
-
-
Save Ravenslofty/889a874e876fcebaefc57a88da317240 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
const ( | |
MoveQuiet byte = iota | |
) | |
type Move struct { | |
From byte | |
To byte | |
Kind byte | |
Promote byte | |
Score int16 | |
} | |
func MoveGen(b *Board) []Move { | |
retval := make([]Move, 0, 32) | |
for i := A1; i <= H8; i++ { | |
if !OnBoard(i) || GetPiece(b.Data[i]) == EMPTY { | |
continue | |
} | |
if GetPiece(b.Data[i]) == PAWN { | |
if b.ToMove == WHITE && !IsBlack(b.Data[i]) { | |
/* Pawn push one square. */ | |
PawnPush := i + 10 | |
/* OnBoard test not needed, since pawns get promoted at rank 8 | |
* and the pawn is not moving to the side. */ | |
if GetPiece(b.Data[PawnPush]) == EMPTY { | |
retval = append(retval, Move{byte(i), | |
byte(PawnPush), MoveQuiet, EMPTY, 0}) | |
} | |
/* Captures are also side-dependent. */ | |
} else if b.ToMove == BLACK && IsBlack(b.Data[i]) { | |
/* Pawn push one square. */ | |
PawnPush := i - 10 | |
/* OnBoard test not needed, since pawns get promoted at rank 8 | |
* and the pawn is not moving to the side. */ | |
if GetPiece(b.Data[PawnPush]) == EMPTY { | |
retval = append(retval, Move{byte(i), | |
byte(PawnPush), MoveQuiet, EMPTY, 0}) | |
} | |
/* Captures are also side-dependent. */ | |
} | |
} else { | |
/* ... */ | |
} | |
} | |
return retval | |
} | |
func MakeMove(b *Board, m *Move) { | |
b.Data[m.To] = b.Data[m.From] | |
b.Data[m.From] = EMPTY | |
b.ToMove ^= BLACK | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment