Git Product home page Git Product logo

connect4's Introduction

Connect4

The game

Long version: see Wikipedia

Each turn, you must select a column to drop a piece of your colour in to. The piece will 'fall' vertically until it hits either another piece or the bottom of the board.

If there are now four pieces in a row (vertically, horizontally or diagonally) of your colour, you win. If there is no space in that column for your piece, you lose.

The game will be drawn if there are no positions left to place pieces in to. Play alternates between players until one of them wins, or the game is a draw.

Additional rules

  • The official interpreter is Ruby 2.0.0
  • The player will not have access to the game objects.
  • The player may require Ruby source files from within a lib directory in the same place as the player file (i.e. players/player.rb can use players/lib/foo/bar.rb via require "foo/bar".)
  • A file should not implement more than one player class.

Implementation

This implementation is based on the ruby implementation for the game Battleships, as found here

Play takes place on a 7x6 grid. Co-ordinates are given in the order (x,y) and are zero-indexed relative to the top left, i.e. (0,0) is the top left, (6,0) is the top right, and (6,5) is the bottom right.

A player is implemented as a Ruby class. The name of the class must be unique and end with Player. It must implement the following instance methods:

name

This must return an ASCII string containing the name of the team or player.

take_turn(state, colour)

state is a representation of the known state of the board, as modified by the player’s moves. It is given as an array of arrays; the inner arrays represent horizontal rows. Each cell may be in one of the following states: :none, :red, :blue, where :red and :blue are the colours of the two players.

colour is the colour that you are playing as, either :red or :blue, for evaluating the board. This will not change between turns, only between games.

take_turn must return a column number to drop a piece into, in the range 0-6.

The console runner

A console runner is provided. It can be started using:

ruby bin/play.rb path/to/player_1.rb path/to/player_2.rb

Players are isolated using DRb.

A couple of very basic players are supplied: StupidPlayer chooses at random. Human Player asks for input via the console.

connect4's People

Contributors

shaun27stars avatar andyh avatar

Watchers

Paul Williams avatar James Cloos 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.