schroedingerchess package

Submodules

schroedingerchess.chess module

First test for chess implementation.

class schroedingerchess.chess.ChessBoard[source]

Bases: object

Chess board manipulation.

add_move_to_history(x1, y1, x2, y2, piece, target_piece)[source]

Add move to history (temporarily or not).

Search all legal move at a given turn.

Search all legal natures a piece could have.

auto_move(intelligent=False)[source]

Perform one of the legal moves at random.

compute_attack()[source]

Encode attack as a binary table.

compute_position()[source]

Encode position as a binary table.

create_standard_board()[source]

Define standard board for test purposes.

delete_move_from_history(x1, y1, x2, y2, piece, target_piece)[source]

Reverse the last move.

display_guess()[source]

Display a possible guess.

display_natures()[source]

Display the number of legal natures.

end_game()[source]
free_trajectory(x1, y1, x2, y2)[source]

Decide if a move is prevented by other pieces in the way.

get_coord(s)[source]

Get coordinates from square number.

get_square(x, y)[source]

Get square number from coordinates.

Check if, given the current history, piece could have nature n.

legal_moves_from(x1, y1)[source]
legal_moves_from_gen(x1, y1)[source]

Search all legal moves starting from a given square.

move(x1, y1, x2, y2, disp=True)[source]

Test and perform a move.

Will raise IllegalMove if the move is not valid.

move_exists(x1, y1, x2, y2)[source]

Verify that a move exists in chess.

nature_elimination(piece, x1, y1, x2, y2)[source]

Find which natures got impossible for the piece that just moved.

on_board(x1, y1)[source]

Check if a square is part of the board.

one_player_game()[source]
parse_variable(var)[source]

Parse pulp variable name.

pawn_could_reach(x1, y1, x2, y2, c)[source]

Check whether a pawn on (x1, y1) can go to (x2, y2).

pawn_could_take(x1, y1, x2, y2, c)[source]

Check whether a pawn on (x1, y1) threatens (x2, y2).

perform_move(x1, y1, x2, y2, problem)[source]

Perform a move, assuming it is valid.

possible_move(x1, y1, x2, y2, n, c)[source]

Decide if a move belongs to the abilities of a piece nature.

Special case for pawns where it depends upon the color, target and the previous moves.

quantum_explanation(check=None)[source]

Perform consistency check with MIP.

Returns the solved linear problem.

test_move(x1, y1, x2, y2, full_result=False)[source]

Test whether a move is possible.

Raise IllegalMove exceptions detailing the various move invalidities.

translate_move(move)[source]
trivial_test_move(x1, y1, x2, y2)[source]

Check obvious failures.

update_guess(problem)[source]

Update guess with MIP solution.

class schroedingerchess.chess.ChessPiece(c, i, n, p, b=None)[source]

Bases: object

Chess piece manipulation.

exception schroedingerchess.chess.IllegalMove[source]

Bases: Exception

Illegal move.

class schroedingerchess.chess.LightBoard[source]

Bases: object

getDeadPieces(color)[source]
getPiece(x, y)[source]
getPieceIndex(x, y)[source]
move(x1, y1, x2, y2)[source]
static possibleNaturesFromMove(x1, y1, x2, y2, color, natures)[source]
setPiece(i, color, position, natures)[source]

i is the index of the piece in self.pieces (same as ChessBoard.pieces)

unwrap(wrap)[source]
wrapUp()[source]
schroedingerchess.chess.main()[source]

Main.

schroedingerchess.client module

class schroedingerchess.client.ChessClientProtocol(client)[source]

Bases: twisted.internet.protocol.Protocol

Class which handles the communication protocol between the game client and the game server.

connectionLost(reason)[source]

Handles the connection lost with the server. :param reason: Reason of the disconnection

connectionMade()[source]

Called when a connection is made.

This may be considered the initializer of the protocol, because it is called when the connection is completed. For clients, this is called once the connection to the server has been established; for servers, this is called after an accept() call stops blocking and a socket has been received. If you need to send any greeting or initial message, do it here.

dataReceived(data)[source]

Handles the reception of data from the server. :param data: A byte representing a JSON-encoded object (default encoding UTF-8)

sendMessage(msg)[source]

Sends a message to the server using the protocol. :param msg: A dictionary representing a message.

split_messages(data)[source]

schroedingerchess.display module

Display chess board.

class schroedingerchess.display.ChessDisplay(gameEngine)[source]

Bases: object

Display of the chess board.

addMessage(message)[source]

Split the incoming text message according to the screen size and add it to the message history :param message: A string message

check_address_format(s)[source]
drawBoard(lightBoard)[source]

Draws the board. :param lightBoard: The light board to draw. :see LightBoard

drawCheckMates(checkmate_positions)[source]

Draws the checkmates created by the last move. :param checkmates_positions: List of the checkmate positions.

drawChecks(check_positions)[source]

Draws the checks created by the last move. :param check_positions: List of the check positions.

drawMenu()[source]

Draws the start menu.

drawPane()[source]
draw_piece(color, natures, x, y, size, extended=False)[source]

x, y are in pixels

flipDisplay(newState)[source]

Set the display orientation :param newState: Is True if and only if the display has to be upside down (Black in the lower part)

flipY(y)[source]

Flip the y coordinate depending on the flip parameter :param y: The y coordinate

handleIllegalMove(reason)[source]

Handles illegal moves. :param reason: Reason of the illegal move

load_images()[source]

Retrieve images from memory.

setLastMove(x1, y1, x2, y2)[source]
setMenuMode()[source]
setOnePlayerOnNetworkMode(name, address, color)[source]

Sets the game engine on the one-player on network mode.

setTwoPlayersOnOneBoardMode()[source]

Sets the game engine on the two-players-on-one-board mode.

update()[source]

Updates the frame.

updateBoard(events)[source]

Handles piece selection and move attempts.

updateMenu(events)[source]

Updates the start menu.

updatePane(events=[])[source]

Update the right hand side pane

class schroedingerchess.display.InputBox(x, y, w, h, text='')[source]

Bases: object

draw(screen)[source]
handle_event(event)[source]
update()[source]

schroedingerchess.game_engines module

class schroedingerchess.game_engines.GameEngine[source]

Bases: object

checkEnd()[source]

Schedules an end check

checkEndTask()[source]

Task to perform to check whether the game has ended.

handleIllegalMove(reason)[source]

Handles an illegal move.

makeDisplayDrawBoard()[source]

Makes the display redraw the board.

makeDisplayDrawChecks(check_positions)[source]
makeDisplayDrawChecksMates(checkmate_positions)[source]
move(x1, y1, x2, y2)[source]

Schedules a move task.

moveTask(x1, y1, x2, y2)[source]

Task to perform when the display detects a move.

resume()[source]

Resumes the reaction loop of the window.

setOnePlayerOnNetworkMode(name, address, color)[source]

Sets the engine on the one-player-on-network mode.

setTwoPlayersOnOneBoardMode()[source]

Sets the engine on the two-players-on-one-board mode.

start()[source]

Starts the game engine. Create the window and initiate the reaction loop.

startFromEngine(engine)[source]

Starts the game engine. Create the window and initiate the reaction loop.

stop()[source]

Stops the game engine.

suspend()[source]

Suspends the reaction loop of the window.

class schroedingerchess.game_engines.OnePlayerOnNetwork(gameEngine, name, address=None, color=0)[source]

Bases: schroedingerchess.game_engines.GameEngine

autoMove()[source]
autoMoveTask()[source]
checkEndTask()[source]

Task to perform to check whether the game has ended.

connectionFailed(*kwargs)[source]
handleCheckMates(description)[source]
handleChecks(description)[source]
handleDisconnection(description)[source]
handleInit()[source]
handleMove(description)[source]

Executes a move received from the server

handleReady()[source]
handleUpdateBoard(description)[source]
moveTask(x1, y1, x2, y2)[source]

Task to perform when the display detects a move.

class schroedingerchess.game_engines.TwoPlayersOnOneBoard(gameEngine)[source]

Bases: schroedingerchess.game_engines.GameEngine

autoMove()[source]
checkEndTask()[source]

Task to perform to check whether the game has ended.

move(x1, y1, x2, y2)[source]

Schedules a move task.

moveTask(mov)[source]

Task to perform when the display detects a move.

updateLightBoard()[source]

schroedingerchess.run module

schroedingerchess.server module

class schroedingerchess.server.ChessServer[source]

Bases: twisted.internet.protocol.Factory

Game server : produces a new ChessServerProtocol each time a client arrives

addWaitingPlayer(client)[source]
assignColor(player_id, color)[source]
protocol

alias of ChessServerProtocol

removeGame(game_id)[source]
removePlayerFromWaitingList(player_id)[source]
tryToMatchPlayers()[source]
class schroedingerchess.server.ChessServerProtocol[source]

Bases: twisted.internet.protocol.Protocol

Class to handles the communication protocol with a game client.

connectionLost(reason)[source]

Handles the connection lost with the client (executes automatically). :param reason: Reason of the disconnection

connectionMade()[source]

Sends the game information when a new client is connected.

dataReceived(data)[source]

Handles the reception of data by the server :param data: A byte representing a JSON-encoded object (default encoding UTF-8)

disconnect()[source]

Disconnect current player / protocol

handleEndGame(color)[source]
handleGreetings(msg)[source]
handleMove(msg, auto=False)[source]
refuseMessage(msg)[source]

Handles the reception of messages when waiting for second player. All instructions are illegal. :param msg: A dictionary representing a message.

sendMessage(msg)[source]

Sends a message to the client. :param msg: A dictionary representing a message.

sendMessageToAll(msg)[source]

Sends a message to the client and the other player’s client. :param msg: A dictionary representing a message.

sendMessageToOther(msg)[source]

Sends a message to the client and the other player’s client. :param msg: A dictionary representing a message.

split_messages(data)[source]
class schroedingerchess.server.Game(whites, blacks, gameIndex)[source]

Bases: object

Class to represent a game instance.

autoMove()[source]
checkEnd(color)[source]
disconnectPlayers()[source]
move(x1, y1, x2, y2, color)[source]
notifyReady()[source]
sendMessageTo(msg, color)[source]
sendMessageToAll(msg)[source]
updateLightBoard()[source]

Schedules an update board task.

updateLightBoardTask()[source]

Module contents