Code Monkey home page Code Monkey logo

c4game's Introduction

c4game

An R package to provide a simple model of the popular family game Connect 4.

Travis-CI Build Status Codecov

Installation

source("https://install-github.me/sellorm/c4game")

...or, if you prefer...

devtools::install_github("sellorm/c4game")

Usage

To play a game against the random bot using the built in REPL ("q" quits):

c4repl()

To play a game against another human:

c4repl(2)

To let the computer play against itself in a random game:

repl(0)

To create your own game object to play with:

game <- c4game$new(board = matrix(, nrow = 6, ncol = 7), player = 1)

This creates a new object called game that you can then interact with.

The game object will have the following fields:

  • board The current state of the game board
  • gamestate Usually just set to 'next' but will report if a win is detected
  • player The current player, 1 or 2

The game object only has one method, dropToken. It takes a single parameter, n, where n is the number of the column the token should be dropped into.

For example:

game$dropToken(3)

Would drop a token into column 3 for the current user in game$player.

At this point, game$board will update, game$gamestate will report either next for "next move" or "Player x wins!", and game$player also updates to reflect the current player number, either 1 or 2.

License

MIT © Mark Sellors

c4game's People

Contributors

dougmet avatar sellorm avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

c4game's Issues

No error checking on dropToken input

This means a player can suggest dropping a token into a non-existent column (eg column 8 in c4repl) which results in an error.

This is be trapped before the error, the situation reported back to the player and game$player should remain not switch to the other player.

Add some tests

There are currently no tests - that needs fixing as a matter of urgency!

Properly support a stalemate

There is currently no support anywhere in the c4game class for a stalemate.

Proper support and a new gamestate should be added to support this scenario.

Support would also need to be added to the getWinner method, which should return NA

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.