Beispiel #1
0
def play_game():
    # Create the game
    game = ChessGame()
    # Create the two players
    player1 = StudentPlayer(Color.WHITE, game, 4)
    player2 = StudentPlayer(Color.BLACK, game, 4)
    move_list = []
    for move in game.play_game(player1, player2, verbose=True):
        move_list.append(move)
Beispiel #2
0
 def __init__(self):
     self._running = True
     #self._display_surf = None
     #self._image_surf = None
     #self._block_surf = None
     #self.board = Board()
     #self.player = Player(self.maze)
     #self.comp = Computer(self.maze, self.player)
     self.game = ChessGame()
Beispiel #3
0
class App:

    windowWidth = 800
    windowHeight = 600
    player = 0

    #!TODO: Create a SURFACE OBJ TO HOLD ALL SURFACES.

    def __init__(self):
        self._running = True
        #self._display_surf = None
        #self._image_surf = None
        #self._block_surf = None
        #self.board = Board()
        #self.player = Player(self.maze)
        #self.comp = Computer(self.maze, self.player)
        self.game = ChessGame()

    def get_user_command(self):
        print('\n')  # Make sure we're on a new line!
        command = input(
            f"Whatcha talkin bout Willis({list(self.game.commands.keys())}): ")
        self.game = self.game.run_command(command)
        self.game.board.printBoard()

    def on_execute(self):
        while True:
            try:
                self.game.doTurn()
                if self.game.gg:  #Check if GameOver
                    break
            except KeyboardInterrupt:
                break
            except EOFError:
                #Get user command
                self.get_user_command()
            except:
                traceback.print_exc()
                pass
Beispiel #4
0
def on_reset_game():
    global game
    global sim
    game = ChessGame()
    sim = game.play_game(player1, player2)
Beispiel #5
0
from flask import Flask, render_template
from flask_socketio import SocketIO, send, emit
from game import ChessGame
from color import Color
from agents import StudentPlayer

# Small Flask app that starts a socket.io server for the game. Run with:
# > FLASK_APP=app.py python3.5 -m flask run

app = Flask(__name__)
app.config['SECRET_KEY'] = 'secret!'
socketio = SocketIO(app)

# Create the chess game
game = ChessGame()
# Create the two players
player1 = StudentPlayer(Color.WHITE, game, 3)
player2 = StudentPlayer(Color.BLACK, game, 3)

# Create a simulation of the game
sim = game.play_game(player1, player2)


@socketio.on('connect')
def on_connect():
    # For each move in the game we send the move to the frontend to be displayed
    # Note that play_game is a generator function and is thus iterable
    emit('server-ready')


@socketio.on('request-move')
Beispiel #6
0
 def play_chess(self):
     render = ConsoleRender()
     game = ChessGame(render)
     game.run()
Beispiel #7
0
        'coord': (5, 4),
        'c': 'black'
    },
    {
        'name': 'rock',
        'coord': (6, 0),
        'c': 'black'
    },
    {
        'name': 'rock',
        'coord': (7, 0),
        'c': 'black'
    },
]

ChessGame.set_players()  #white_config=white_conf, black_config=black_conf)

Interface.add_resizable_objs(ChessGame.players['white'].pieces)
Interface.add_resizable_objs(ChessGame.players['black'].pieces)

LivePlay.ChessGame = ChessGame
LivePlay.menu = menu

# agent_white = bruteforce.Agent('white', ChessGame)
# agent_black = bruteforce.Agent('black', ChessGame)

ChessGame.set_control_methods(LivePlay('white'), LivePlay('black'))

# Tests.run(ChessGame)

while Interface.running:
Beispiel #8
0
def main():
    renderer = ConsoleRenderer()
    game = ChessGame(renderer)
    game.run()