Coder Social home page Coder Social logo

cannon-bot's Introduction

Cannon

Simulator supporting a user interface for Cannon, an abstract strategy board game.

Details

This is a course assignment for the graduate-level Artificial Intelligence course taught by Prof. Mausam.
The assignment documentation can be found here

Teaching Assistants

Rules

The rules of the original game can be found here

However, we will be having an 8x8 board and 4 Town Halls instead of 1. The position of the Town Halls is fixed. Further instructions are mentioned in the Assignment Document.

Dependencies

  • Python2.7
  • Chrome Webdriver
  • Jinja2
  • Multiset
  • Numpy
  • Selenium

pip install -r requirements.txt

Download the chrome driver executable according to your chrome version from the following link: https://chromedriver.chromium.org/downloads

You can check you chrome version following the steps below:

  • Launch Google Chrome.
  • Click on the icon in the upper right corner that looks like 3 short bars.
  • Select About Google Chrome to display the version number.

Main Files

  • game.py - This has an instance of the game. It can be run locally to hand play a game of Cannon or re-play a recorded game. Should be run in GUI mode to make game board visible.
  • RandomPlayer.py - This is an implementation of a random bot. It is a good place to start understanding the flow of the game and the various game states.
  • client.py - This will encapsulate your process and help it connect to the game server.

    ip (mandatory) - The Server IP.
    port (mandatory) - The Server Port.
    exe (mandatory) - The Executable.
    mode (optional) - The View Mode ('GUI' / 'CUI'). Default: 'CUI'

  • server.py - This connects the clients and manages the transfer of information.

    port (mandatory) - The Server Port.
    ip (optional) - The Server IP. Default: 0.0.0.0
    n (optional) - The Board Size. Default: 8
    NC (optional) - Number of Clients. Default: 2
    TL (optional) - Time Limit. Default:150
    LOG (optional) - The Log File.

Run Instructions

Here are the sample instructions used to match two random players against each other over the server network.

Setup Server

python server.py 10000 -n 8 -m 8 -NC 2 -TL 150 -LOG server.log

Setup Client 1

export PATH=$PATH:'/home/chrome_driver_directory'

python client.py 0.0.0.0 10000 RandomPlayer.py -mode GUI

Setup Client 2

export PATH=$PATH:'/home/chrome_driver_directory'

python client.py 0.0.0.0 10000 RandomPlayer.py

Gameplay

The game play consists of the players executing a sequence of moves in a single turn. A move is a triple: type x y.

Movetype

  • S - Select a soldier
  • M - Move a soldier
  • B - Throw a Bomb

Board Settings

The board is an n x m board. The top-left corner point is the origin. The horizontal direction towards the right is the positive x-axis. The vertical direction towards down is the positive y-axis. The indexing begins with 0 in both the directions.

Moving a Soldier

To move a soldier from (1, 2) to (2, 4).

S 1 2 M 2 4

Throwing a Bomb

To throw a bomb, select any of the soldiers of a cannon, and throw it at any viable target of the cannon(s) formed by that soldier.

S 2 4 B 6 4

Replay

A server.log file is created during the gameplay that consist of the moves played in the game. You can simulate/re-run it using the following command:

python game.py server.log

Scoring

At the end of a game both players will be given a score.

The Town Hall Margin

This score will be based on the extent of victory. It is calculated as follows:

Your Town Halls Remaining Opponent's Town Halls Remaining Town Hall Margin Score
4 2 10
3 2 8
4 3 7
4 4 5
3 3 5
3 4 3
2 3 2
2 4 0

The Army Margin

This score directly depends on the number of soldiers you have left at the end of the game. It is calculated as follows:
Army Margin Score = # (Soldiers Remaining) / 100

Final Score

The final score is simply: (Town Hall Margin Score).(Army Margin Score) Example. Assume the following:
Player 1 has 3 Town Halls remaining and has 12 soldiers left on the board.
Player 2 has 2 Town Hall remaining and has 9 soldiers left on the board.
Player 1 score will be: 8.12
Player 2 score will be: 2.09

Note) In case a player suffers a TIMEOUT or INVALID move, he/she will automatically lose the gane and it will count as a (2-x) defeat towards the player and a (x-2) win for the opponent, where x is the number of Town Halls remaining with the opponent.

cannon-bot's People

Contributors

vardhanjain2012 avatar shivambansal99 avatar

Watchers

James Cloos avatar  avatar  avatar

Forkers

vardhanjain2012

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.