marcusbuffett / command-line-chess

A python program to play chess against an AI in the terminal.
MIT License
500 stars 162 forks source link

Castling maybe not working #9

Closed mkondel closed 6 years ago

mkondel commented 8 years ago

Just as an example, here is the board, player is white. As you can see, castling is not in the list of possible moves. There is a Board.getShortNotationOfMove() that should return '0-0-0' and '0-0', but move.kingsideCastle and move.queensideCastle are not getting recognized at that point.

It's your move. Type '?' for options. ? 0-0
command: 0-0
move None
Couldn't parse input, enter a valid command or move.
   a b c d e f g h   

8  R N B Q K B N R  8
7  x p x p p p x p  7
6  p x x x x x x x  6
5  x x p x x x p x  5
4  x x B x p x x x  4
3  x x x x x N x x  3
2  p p p p x p p p  2
1  R N B Q K x x R  1

   a b c d e f g h

Currently, the point difference is : 0
It's your move. Type '?' for options. ? o-o
command: o-o
move None
Couldn't parse input, enter a valid command or move.
   a b c d e f g h   

8  R N B Q K B N R  8
7  x p x p p p x p  7
6  p x x x x x x x  6
5  x x p x x x p x  5
4  x x B x p x x x  4
3  x x x x x N x x  3
2  p p p p x p p p  2
1  R N B Q K x x R  1

   a b c d e f g h

Currently, the point difference is : 0
It's your move. Type '?' for options. ? O-O
command: o-o
move None
Couldn't parse input, enter a valid command or move.
   a b c d e f g h   

8  R N B Q K B N R  8
7  x p x p p p x p  7
6  p x x x x x x x  6
5  x x p x x x p x  5
4  x x B x p x x x  4
3  x x x x x N x x  3
2  p p p p x p p p  2
1  R N B Q K x x R  1

   a b c d e f g h

Currently, the point difference is : 0
It's your move. Type '?' for options. ? 0-0-0
command: 0-0-0
move None
Couldn't parse input, enter a valid command or move.
   a b c d e f g h   

8  R N B Q K B N R  8
7  x p x p p p x p  7
6  p x x x x x x x  6
5  x x p x x x p x  5
4  x x B x p x x x  4
3  x x x x x N x x  3
2  p p p p x p p p  2
1  R N B Q K x x R  1

   a b c d e f g h

Currently, the point difference is : 0
It's your move. Type '?' for options. ? o-o-o
command: o-o-o
move None
Couldn't parse input, enter a valid command or move.
   a b c d e f g h   

8  R N B Q K B N R  8
7  x p x p p p x p  7
6  p x x x x x x x  6
5  x x p x x x p x  5
4  x x B x p x x x  4
3  x x x x x N x x  3
2  p p p p x p p p  2
1  R N B Q K x x R  1

   a b c d e f g h

Currently, the point difference is : 0
It's your move. Type '?' for options. ? O-O-O
command: o-o-o
move None
Couldn't parse input, enter a valid command or move.
   a b c d e f g h   

8  R N B Q K B N R  8
7  x p x p p p x p  7
6  p x x x x x x x  6
5  x x p x x x p x  5
4  x x B x p x x x  4
3  x x x x x N x x  3
2  p p p p x p p p  2
1  R N B Q K x x R  1

   a b c d e f g h

Currently, the point difference is : 0
It's your move. Type '?' for options. ? l
command: l
a3
a4
b3
b4
c3
d3
d4
e5
g3
g4
h3
h4
Nc3
Na3
Qe2
Ke2
Kf1
Bd5
Be6
Bxf7
Bd3
Be2
Bf1
Bb5
Bxa6
Bb3
Nh4
Nd4
Nxg5
Ng1
Ne5
Rg1
Rf1
   a b c d e f g h   

8  R N B Q K B N R  8
7  x p x p p p x p  7
6  p x x x x x x x  6
5  x x p x x x p x  5
4  x x B x p x x x  4
3  x x x x x N x x  3
2  p p p p x p p p  2
1  R N B Q K x x R  1

   a b c d e f g h

Currently, the point difference is : 0
It's your move. Type '?' for options. ?
jonathanMelly commented 6 years ago

Same issue for me, as I saw in the code, the parser is not ready, nor the available moves report castling :-( Time for a fork ;-)

ddugovic commented 6 years ago

I can fix this. For a start, it appears all the + and - symbols are backwards, although then the game crashes (during my testing the AI played Ng4xh2 just before this!):

Making move : Nxh2
   a b c d e f g h

8  R N B Q K B x R  8
7  p p p p p p p p  7
6  x x x x x x x x  6
5  x x x x x x x x  5
4  x x x x x x x x  4
3  x x x x x x p x  3
2  p p p p p p B N  2
1  R N B Q K x x R  1

   a b c d e f g h

AI thinking...

Making move : a5
   a b c d e f g h

8  R N B Q K B x R  8
7  x p p p p p p p  7
6  x x x x x x x x  6
5  p x x x x x x x  5
4  x x x x x x x x  4
3  x x x x x x p x  3
2  p p p p p p B N  2
1  R N B Q K x x R  1

   a b c d e f g h

Traceback (most recent call last):
  File "src/main.py", line 130, in <module>
    startGame(board, playerSide, opponentAI)
  File "src/main.py", line 78, in startGame
    if board.isCheckmate():
  File "/home/lila/command-line-chess/src/Board.py", line 125, in isCheckmate
    if len(self.getAllMovesLegal(self.currentSide)) == 0:
  File "/home/lila/command-line-chess/src/Board.py", line 411, in getAllMovesLegal
    if self.moveIsLegal(move):
  File "/home/lila/command-line-chess/src/Board.py", line 401, in moveIsLegal
    self.makeMove(move)
  File "/home/lila/command-line-chess/src/Board.py", line 332, in makeMove
    self.movePieceToPosition(rookToMove, move.rookMovePos)
AttributeError: 'Move' object has no attribute 'rookMovePos'

Fixing makeMove then results in command l being able to list the move, although I can't play O-O.

It's your move. Type '?' for options. ? O-O
Couldn't parse input, enter a valid command or move.
   a b c d e f g h

8  R x B Q K B N R  8
7  p x p p p p x p  7
6  N p x x x x x x  6
5  x x x x x x p x  5
4  x x x x x x x x  4
3  x x x x x N p x  3
2  p p p p p p B p  2
1  R N B Q K x x R  1

   a b c d e f g h
jonathanMelly commented 6 years ago

Well done, thanks for that first patch ;-)

ddugovic commented 6 years ago

Glad to submit a patch the entire community may benefit from!