JoscarJiang / OurReversi

A simple Reversi Game with Monte Carlo Tree Search

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Reversi Game

Schedule

Task Due Responsibility Done
Reconstruction Apr 10, 24:00 UTC + 8 Stephen Tse
GUI Apr 10, 24:00 UTC + 8 chchenhui TODO
MCTS Apr 10, 24:00 UTC + 8 Joscar Jiang TODO

Dependencies

  • pygame
  • gevent

How to run

Run the Server Program on Local Host

First, run the server

python2 server.py

Then, run two clients to play against each other

python2 player.py human -g  # for human player, add -g flag to enable gui
python2 player.py mcts   # for AI, @NOTE AI does not have gui by now

Or you can run two AIs and watch them to play.

Run the Server Program on a Remote Server

First, run the server

python2 server.py 0.0.0.0 4242  # you should specify address and port number

Then, run two clients to play against each other

python2 player.py human -g http://qcloud.stse.me 4242 # for human player, add -g flag to enable gui, you should specify address and port number
python2 player.py mcts http://qcloud.stse.me 4242  # for AI, @NOTE AI does not have gui by now

Note

If you shut down one client, to make things work again, you have to shut down the server and the other client and then restart them.

Message Conventions

Message type:

  • player
  • update
  • action
  • decline
  • error
  • illegal

Note: update message has the following keys: state, type, board, last_action, winners, and points.

Examples

When client connects to server, server sends the player number.

{
    "message": 2,
    "type": "player"
}

It's player 1's turn.

{
    "state": {
        "player": 1,
        "previous_player": 2,
        "pieces": [{
            "column": 3,
            "player": 2,
            "type": "disc",
            "row": 3
        }, {
            "column": 4,
            "player": 1,
            "type": "disc",
            "row": 3
        }, {
            "column": 3,
            "player": 1,
            "type": "disc",
            "row": 4
        }, {
            "column": 4,
            "player": 2,
            "type": "disc",
            "row": 4
        }]
    },
    "type": "update",
    "board": null
}

It's player 2's turn.

{
    "state": {
        "player": 2,
        "previous_player": 1,
        "pieces": [{
            "column": 2,
            "player": 1,
            "type": "disc",
            "row": 3
        }, {
            "column": 3,
            "player": 1,
            "type": "disc",
            "row": 3
        }, {
            "column": 4,
            "player": 1,
            "type": "disc",
            "row": 3
        }, {
            "column": 3,
            "player": 1,
            "type": "disc",
            "row": 4
        }, {
            "column": 4,
            "player": 2,
            "type": "disc",
            "row": 4
        }]
    },
    "type": "update",
    "board": null,
    "last_action": {
        "player": 1,
        "notation": "c4",
        "sequence": 2
    }
}

Player 2 sends its action to server.
``` json
{
    "message": "c5",
    "type": "action"
}

Player 1's turn again.

{
    "state": {
        "player": 1,
        "previous_player": 2,
        "pieces": [{
            "column": 2,
            "player": 1,
            "type": "disc",
            "row": 3
        }, {
            "column": 3,
            "player": 1,
            "type": "disc",
            "row": 3
        }, {
            "column": 4,
            "player": 1,
            "type": "disc",
            "row": 3
        }, {
            "column": 2,
            "player": 2,
            "type": "disc",
            "row": 4
        }, {
            "column": 3,
            "player": 2,
            "type": "disc",
            "row": 4
        }, {
            "column": 4,
            "player": 2,
            "type": "disc",
            "row": 4
        }]
    },
    "type": "update",
    "board": null,
    "last_action": {
        "player": 2,
        "notation": "c5",
        "sequence": 3
    }
}

Player 2's turn again. Note that if someone wins, we will receive "winner" information

{
    "state": {
        "player": 2,
        "previous_player": 1,
        "pieces": [{
            "column": 2,
            "player": 1,
            "type": "disc",
            "row": 3
        }, {
            "column": 3,
            "player": 1,
            "type": "disc",
            "row": 3
        }, {
            "column": 4,
            "player": 1,
            "type": "disc",
            "row": 3
        }, {
            "column": 2,
            "player": 1,
            "type": "disc",
            "row": 4
        }, {
            "column": 3,
            "player": 1,
            "type": "disc",
            "row": 4
        }, {
            "column": 4,
            "player": 2,
            "type": "disc",
            "row": 4
        }, {
            "column": 2,
            "player": 1,
            "type": "disc",
            "row": 5
        }]
    },
    "winners": {"1": 1, "2": 0},
    "type": "update",
    "board": null,
    "last_action": {
        "player": 1,
        "notation": "c6",
        "sequence": 4
    }
}

About

A simple Reversi Game with Monte Carlo Tree Search


Languages

Language:Python 100.0%