Skip to content
This repository has been archived by the owner on Sep 19, 2023. It is now read-only.

Commit

Permalink
Add separate move and full move stringers.
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo-stoakes committed Aug 28, 2012
1 parent 04c3700 commit a7a8690
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 19 deletions.
4 changes: 2 additions & 2 deletions game.c
Expand Up @@ -280,7 +280,7 @@ DoMove(Game *game, Move move)
if((msg = checkConsistency(game)) != NULL) {
printf("Inconsistency in %s's DoMove of %s at doMoveCount %llu:-\n\n",
StringSide(side),
StringMove(move, piece, capturePiece != MissingPiece),
StringMoveFull(move, piece, capturePiece != MissingPiece),
doMoveCount);
puts(StringChessSet(chessSet));
puts(msg);
Expand Down Expand Up @@ -773,7 +773,7 @@ Unmove(Game *game)
if((msg = checkConsistency(game)) != NULL) {
printf("Inconsistency in %s's Unmove of %s at unmoveCount %llu:-\n\n",
StringSide(side),
StringMove(move, piece, capturePiece != MissingPiece),
StringMoveFull(move, piece, capturePiece != MissingPiece),
unmoveCount);
puts(StringChessSet(chessSet));
puts(msg);
Expand Down
4 changes: 2 additions & 2 deletions interface.c
Expand Up @@ -74,15 +74,15 @@ RunInterface(Game *game)
fromPiece = PieceAt(&game->ChessSet, FROM(reply));
capture = PieceAt(&game->ChessSet, TO(reply)) != MissingPiece;
DoMove(game, reply);
puts(StringMove(reply, fromPiece, capture));
puts(StringMoveFull(reply, fromPiece, capture));

break;
case CmdMoves:
end = AllMoves(moves, game);

printf("%ld moves:-\n\n", end-moves);
for(curr = moves; curr != end; curr++) {
puts(StringMove(*curr, PieceAt(&game->ChessSet, FROM(*curr)),
puts(StringMoveFull(*curr, PieceAt(&game->ChessSet, FROM(*curr)),
PieceAt(&game->ChessSet, TO(*curr)) != MissingPiece));
}
printf("\n");
Expand Down
17 changes: 10 additions & 7 deletions movegen.c
Expand Up @@ -19,11 +19,12 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include <stdio.h>

#include "weak.h"
#include "magic.h"

static FORCE_INLINE Move* bishopMoves(Position*, Move*, BitBoard, BitBoard);
static Move* evasions(Move*, Game*);
static Move* evasionsCaptures(Move*, Game*);
static FORCE_INLINE Move* kingMoves(Position, Move*, BitBoard);
static FORCE_INLINE Move* knightMoves(Position*, Move*, BitBoard);
Expand All @@ -40,14 +41,16 @@ Move*
AllCaptures(Move *start, Game *game)
{
Move *curr = start, *end = start;
Move move;

end = game->CheckStats.CheckSources ?
evasionsCaptures(start, game) :
nonEvasionsCaptures(start, game);

// Filter out illegal moves.
while(curr != end) {
if(!PseudoLegal(game, *curr, game->CheckStats.Pinned)) {
move = *curr;
if(!PseudoLegal(game, move, game->CheckStats.Pinned)) {
// Switch last move with the one we are rejecting.
end--;
*curr = *end;
Expand All @@ -64,7 +67,7 @@ AllMoves(Move *start, Game *game)
{
Move *curr = start, *end = start;

end = game->CheckStats.CheckSources ? evasions(start, game) : nonEvasions(start, game);
end = game->CheckStats.CheckSources ? Evasions(start, game) : nonEvasions(start, game);

// Filter out illegal moves.
while(curr != end) {
Expand Down Expand Up @@ -208,14 +211,14 @@ CastleMoves(Game *game, Move *end)
return end;
}

static Move*
evasions(Move *end, Game *game)
Move*
Evasions(Move *end, Game *game)
{
BitBoard attacks, moves, targets;
BitBoard checks = game->CheckStats.CheckSources;
BitBoard slideAttacks = EmptyBoard;
ChessSet *chessSet = &game->ChessSet;
BitBoard occupancy = chessSet->Occupancy;
BitBoard occupancy = chessSet->Occupancy;
int checkCount = 0;
Piece piece;
Position check;
Expand Down Expand Up @@ -296,7 +299,7 @@ evasionsCaptures(Move *end, Game *game)
BitBoard checks = game->CheckStats.CheckSources;
BitBoard slideAttacks = EmptyBoard;
ChessSet *chessSet = &game->ChessSet;
BitBoard occupancy = chessSet->Occupancy;
BitBoard occupancy = chessSet->Occupancy;
int checkCount = 0;
Piece piece;
Position check;
Expand Down
23 changes: 16 additions & 7 deletions stringer.c
Expand Up @@ -223,9 +223,20 @@ StringChessSet(ChessSet *chessSet)
return strdup(ret);
}

char*
StringMove(Move move)
{
char ret[5];

sprintf(ret, "%s%s", StringPosition(FROM(move)),
StringPosition(TO(move)));

return strdup(ret);
}

// String move in long algebraic form.
char*
StringMove(Move move, Piece piece, bool capture)
StringMoveFull(Move move, Piece piece, bool capture)
{
char actionChr, pieceChr;
char *suffix, *from, *to;
Expand Down Expand Up @@ -288,19 +299,17 @@ StringMoveHistory(MemorySlice *history)
StringBuilder builder = NewStringBuilder();
int fullMoveCount = 1;

// TODO: Determine positions + capture condition for moves.

for(curr = history->Vals; curr != history->Curr; curr++) {
move = curr->Move;

switch(side) {
case White:
AppendString(&builder, "%d. ?%s",
fullMoveCount, StringMove(move, Pawn, false));
AppendString(&builder, "%d. %s",
fullMoveCount, StringMove(move));
break;
case Black:
AppendString(&builder, " ?%s\n",
StringMove(move, Pawn, false));
AppendString(&builder, " %s\n",
StringMove(move));

fullMoveCount++;

Expand Down
3 changes: 2 additions & 1 deletion weak.h
Expand Up @@ -600,7 +600,8 @@ MoveSlice NewMoveSlice(Move*);
char CharPiece(Piece);
char* StringBitBoard(BitBoard);
char* StringChessSet(ChessSet*);
char* StringMove(Move, Piece, bool);
char* StringMove(Move);
char* StringMoveFull(Move, Piece, bool);
char* StringMoveHistory(MemorySlice*);
char* StringPerft(PerftStats*);
char* StringPiece(Piece);
Expand Down

0 comments on commit a7a8690

Please sign in to comment.