Giter VIP home page Giter VIP logo

box-take-home's Introduction

MiniShogi Game

This project allows two people to play mini shogi via a command line interface. For more details on how to interact with the game, see the section on Getting Started > Game Modes.

The project was written in Python 3.5.3. There are no pip packages used, so you should be able to just run the project aftering cloning the repository. However, if you are attempting to run the program via Windows, you will most likely have to modify your PYTHONPATH to contain the path of this project. Otherwise, Windows will not recognize any of the classes as modules when some files try to import them.

Getting Started

All of the example commands listed in this README assume that you are in the root directory of the project. If not, just update the commands to have the relative filepath to your current directory.

Game Modes

In interactive mode, two players enter keyboard commands to play moves against each other. Interactive mode can be started with the following command:

python src/myShogi.py -i

In file mode, the specified file is read to determine the game state and which moves to make. File mode is how the game logic is tested in this project. You can see a list of the tests for this project here. File mode can be started with the following command:

python src/myShogi.py -f Tests/<inputTestCaseName>

If you wish to see more detailed output as to what is happening behind the scenes, you can activate debug mode with a -d parameter. Specifying debug mode in the interactive game mode would look like this:

python src/myShogi.py -d -i

It should be noted that if you run debug mode with file game mode and try to diff the output, it will not match the expected output of the testcase you are running. Specifying debug mode in the file game mode would look like this:

python src/myShogi.py -d -f Tests/<inputTestCaseName>

Testing

The tests in the project validate the correctness of this implementation of mini shogi. If you wish to run any single test case and diff the output, you can run the following command:

python src/myShogi.py -f Tests/<inputTestCaseName> | diff -u Tests/<outputTestCaseName> -

Alternatively, RunTestsWithDiff.sh is bash script that will automatically run all tests and diff the output with the expected output. You can expect to see output that looks like the following screenshot:

RunTestsWithDiff Output

Design

You can find specific design in the src directory.

Performance

There are a few computationally expensive functions, mainly involved with generating moves to escape check and checking whether or not a player is in checkmate. However, this fact does not necessarily affect the execution of the program too much because of the limited input size of variables and conditions of the game. For example, there are a max of 12 pieces in the game, the board is a max size of 5x5, and there can only be 400 moves before the game ends in a tie. So, despite some expensive functions, the execution of the game isn't slowed down by too much.

Error Handling

For most general errors that could occur such as an input file not existing, an error message will be printed to the screen but the execution of the game will end immediately instead of allowing unhandled exceptions to be printed in the console.

Errors such as an action other than move or drop or an invalid board position will result in the game ending as a result of an INVALID MOVE.

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.