StockFish Wannabe

A chess engine that uses a neural network trained on Stockfish Evaluations as its position evaluator.

Was intended to be a demonstration of the capabilities of ANNs. Ended up being more a demonstration of their… limitations. .. currentmodule:: stockfish_wannabe.stockfish_wannabe

class stockfish_wannabe.Chess[source]
eval()[source]

Returns what the engines neural network thinks the evaluation of the position is Returns:

A number between 0 and 229 inclusive. An evaluation n between 0 and 14 means mate for black in n moves. An evalation n between 15 and 214 inclusive means an evaluation of (n - 115) * 10 centipawns. An evaluation n between 215 and 229 inclusive means mate for white in 229 - n moves. This evaluation sadly isn’t very accurate.

findBestMove(depth, isBlack)[source]

Find the best move in the current position.

Args:

depth: How many moves deep it should evaluate isBlack: If true, the engien will try to find the best move for black. Otherwise, it will try to find the best move for white.

Returns:

The best move in the current position, the evaluation if said move is played

gameMessage()[source]

Returns a message describing how the game ended, or None if the game isn’t over

Returns:

“WHITE won” if white has won, “BLACK won” if black has won, or “DRAW” if the game is drawn

isGameOver()[source]

Checks if the game is over. Returns:

True if the game has ended, False otherwise

largestIndex(arr)[source]

Finds the index of the largest value in an array Arguments:

arr: Array we are parsing

Returns:

The index of the largest value, or first occurence if the largest occurs more than once

makeMove(move)[source]

Inputs a move to the engine

Args:

move: A move to make in Standard Notateion (Ex: NF3)

Raises:

Value Error: If any string does not represent a legal series of ches moves

play()[source]

Allows the user to play against this program’s chess engine from the current position.

playAs(color: str)[source]

Sets the color that the player will be playing Args:

color, either “w” for white or “b” for black

Raises:

ValueError: When the provided color isn’t a valid chess color.

reset()[source]

Resets the chessboard to the original starting position

setup(moveString: str)[source]

Sets the board up to a starting position

Args:

moveString: A series of moves in SAN seperated by commas. For example, “e4,e5” will cause the position the board to make the moves e4, then e5

Raises:

The best move, the evaluation if said move is made.

takeBack()[source]

Undoes the last move made