cogsys-tuebingen / ai_competition Goto Github PK
View Code? Open in Web Editor NEWRepository for the diana chess competition. AI Lecture 21/22
Repository for the diana chess competition. AI Lecture 21/22
Sometimes when I run my agent, I got an error that on after checking if the move is a capture the moving figure doesnt match the figure names.
After further investiagation I found out that when my Quiesce function do recursivly moves without checking if the game is over, you can create a move with '--' as playing figure.
With the addition in ChessEngine.py:800
if(self.pieceMoved == "--"): raise ValueError('moving a piece that is not on the board')
I got the following console output:
Process Process-1:
Traceback (most recent call last):
File "C:\Python39\lib\multiprocessing\process.py", line 315, in _bootstrap
self.run()
File "C:\Python39\lib\multiprocessing\process.py", line 108, in run
self._target(*self._args, **self._kwargs)
File "C:\Projekte\chess_ai\student_agents\template.py", line 107, in findBestMove
score = self.alphaBeta(copyGS, self.currentDepth, -float('inf'), float('inf'), True)
File "C:\Projekte\chess_ai\student_agents\template.py", line 284, in alphaBeta
score = self.alphaBeta(copyGS, depth - 1, alpha, beta, False)
File "C:\Projekte\chess_ai\student_agents\template.py", line 319, in alphaBeta
score = self.alphaBeta(copyGS, depth - 1, alpha, beta, True)
File "C:\Projekte\chess_ai\student_agents\template.py", line 264, in alphaBeta
return self.Quiesce(gs,alpha,beta,depth)
File "C:\Projekte\chess_ai\student_agents\template.py", line 388, in Quiesce
score = -self.Quiesce(gs, -beta, -alpha ,depth)
File "C:\Projekte\chess_ai\student_agents\template.py", line 388, in Quiesce
score = -self.Quiesce(gs, -beta, -alpha ,depth)
File "C:\Projekte\chess_ai\student_agents\template.py", line 388, in Quiesce
score = -self.Quiesce(gs, -beta, -alpha ,depth)
[Previous line repeated 1 more time]
File "C:\Projekte\chess_ai\student_agents\template.py", line 384, in Quiesce
validMoves = gs.getValidMoves()
File "C:\Projekte\chess_ai\ChessEngine.py", line 300, in getValidMoves
self.getKingMoves(kingRow, kingCol, moves)
File "C:\Projekte\chess_ai\ChessEngine.py", line 688, in getKingMoves
moves.append(Move((r, c), (endRow, endCol), self.board))
File "C:\Projekte\chess_ai\ChessEngine.py", line 800, in __init__
raise ValueError('moving a piece that is not on the board')
ValueError: moving a piece that is not on the board
There you can see that when you execute gs.getValidMoves()
on a Board without a king it returns a move where '--' is the moving Figure
Sometimes the function getKingsideCastleMoves
get called with index=35
and with
getKingsideCastleMoves
in ChessEngine:732
if self.board[rc + 1] == "--":
it ends in an IndexError
File "C:\Projekte\chess_ai\student_agents\template.py", line 313, in alphaBetaMin
validMoves = gs.getValidMoves()
File "C:\Projekte\chess_ai\ChessEngine.py", line 306, in getValidMoves
self.getCastleMoves(kingRow, kingCol, moves)
File "C:\Projekte\chess_ai\ChessEngine.py", line 708, in getCastleMoves
self.getKingsideCastleMoves(r, c, moves)
File "C:\Projekte\chess_ai\ChessEngine.py", line 732, in getKingsideCastleMoves
if self.board[rc + 1] == "--":
IndexError: list index out of range
Checkmates are not detected if they happen within a pawn promotion move.
Board:
-- bK -- -- -- --
-- -- -- wR wp --
-- -- -- -- -- --
-- -- -- -- -- --
-- -- -- -- -- --
-- -- wK -- -- --
White's turn.
Valid moves: ['Ra5', 'Rd2', 'Rc5', 'Kc2', 'e6', 'Rd1', 'Kd2', 'Rb5', 'Rd4', 'Kb1', 'Kd1', 'Rd3', 'Kb2', 'Rd6']
White makes move: 'e6'
Board:
-- bK -- -- wR --
-- -- -- wR -- --
-- -- -- -- -- --
-- -- -- -- -- --
-- -- -- -- -- --
-- -- wK -- -- --
Pawn gets promoted to Rook. Black King is in Checkmate (gameState.checkMate evaluates to True
)
Pawn gets promoted to Rook. Black King is not in Checkmate (gameState.checkMate evaluates to False
)
I run my agent and suddenly I saw this:
On the right bottom corner was my rook and now my own knight is there. That alone is defently not a valid move.
Furthermore you can see the last position of my knight as red dot. So there is also an unvalid move from there as knight.
Maybe there are some bugs in the Castle Right moves...
You can test that behavior with that code:
gs = GameState()
gs.board = ['bR', 'bB', 'bK', 'bN', '--', 'bR',
'bp', 'bp', '--', '--', '--', 'bp',
'--', '--', '--', 'bp', '--', 'wp',
'--', '--', '--', '--', '--', '--',
'bB', 'wp', 'wp', 'wp', '--', '--',
'wR', 'wB', 'wK', 'wN', '--', 'wR']
gs.whiteToMove = True
moves = gs.getValidMoves()
it dont happen very often but when it happen I cannot found any problem in my code.
I'm using undo move like this in my code
gs.makeMove(move)
score = RekursiveFunktion(x,y)
gs.undoMove()
Process Process-6:
Traceback (most recent call last):
File "C:\Projekte\chess_ai\ChessEngine.py", line 177, in undoMove
self.game_log[tuple(self.board)] -= 1
KeyError: ('--', 'bR', 'bN', 'bK', 'bB', 'bR', '--', 'bp', 'bp', '--', 'bp', 'bp', '--', 'bB', '--', 'bp', '--', '--', '--', '--', '--', 'wp', 'wp', 'wp', 'wp', 'wp', 'wp', '--', '--', 'wR', 'wR', 'wB', 'wN', 'wK', '--', 'wR')
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.