Git Product home page Git Product logo

8woc2018_reversi's Introduction

Reversi Challenge

What is Reversi?

Reversi is a simple board game played on an 8x8 board with black and white disks. You can find detailed rules to the game on Wikipedia:

https://en.wikipedia.org/wiki/Reversi

Your challenge

Write a command-line program in the language of your choice that:

An example Python script, example_solution_template.py that reads from stdin and writes to stdout is provided. It does not solve the challenge, however -- that's up to you!

Your program will be called by sending your program a JSON board state through its stdin, and its performance will be evaluated based on the JSON board state your program prints to its stdout. The formatting of your output JSON does not matter -- only the structure and values need to match the expected output.

The next sections describe the input that will be given to your program, and the output that is expected from it:

Input

Your input will be a JSON object containing a board state and a player move; for example:

{
    "board": [
                0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 2, 1, 0, 0, 0,
                0, 0, 0, 1, 2, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0
             ],
    "move":  {
                "player": 1,
                "column": 4,
                "row":    3
             }
}

board is an array of integers of length 64, conceptually arranged in rows and columns. Counting from zero:

  • Item 0 is the upper-left cell of the board.
  • Item 7 is the upper-right cell of the board.
  • Item 56 is the lower-left cell of the board.
  • Item 63 is the lower-right cell of the board.

move is an object describing the next move:

  • player: Either 1 (black) or 2 (white)
  • column: A value from 1 (leftmost column) to 8 (rightmost column)
  • row: A value from 1 (top column) to 8 (bottom column)

Output

Your output must be a JSON object containing the new board state after applying the player's move; for example:

{
    "board": [
                0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 1, 0, 0, 0, 0,
                0, 0, 0, 1, 1, 0, 0, 0,
                0, 0, 0, 1, 2, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0
             ]
}

board: Same structure as the board array in the input.

How to Start

You can find some starting materials on GitHub. You don't need to be able to run these Python scripts to create your program, but you may find them helpful to verify that your code works.

https://github.com/WycliffeAssociates/8woc2018_reversi

tests/tests.json

This is a set of tests that will be run against your code. Your code must pass at least these tests. Each test contains an input object that is passed to your program's stdin as JSON, and an expected object that is compared against your program's output to stdout.

An excerpt from the file containing one test is shown below:

[
  {
    "input": {
      "board": [
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 2, 1, 0, 0, 0,
        0, 0, 0, 1, 2, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0
      ],
      "move": {
        "player": 1,
        "column": 4,
        "row":    3
      }
    },
    "expected": {
      "board": [
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 1, 0, 0, 0, 0,
        0, 0, 0, 1, 1, 0, 0, 0,
        0, 0, 0, 1, 2, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0
      ]
    }
  },
  ...
]

tester.py

A Python script that runs the tests against an executable. You may find it helpful to run this against your executable to ensure the tests pass. It will print a JSON object containing the result of the test, and return 1 if any of the tests failed.

# Run tester
./tester.py ./your-executable > test_results.json

example_solution_template.py

A sample executable that naively returns the board state it was given. This will fail all tests.

# Test naive executable
./tester.py ./example_solution_template.py > all_tests_fail.json
# Print errorlevel of 1 (at least one test failed)
echo $? 

8woc2018_reversi's People

Contributors

purpleguitar avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

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.