Giter Site home page Giter Site logo

matchsticks-nim-react's Introduction

matchsticks

a react-powered, 2-player nim-game


what's a nim-game?

Nim is a game of mathematical strategy, mostly involving subtraction. As Wikipedia will tell you, players alternatively take objects from 'heaps,' taking as many objects from one heap as they like, but only from one heap per turn.

The objective of the game is to leave only one object for the other player to take. In other words: don't take the last object!


tech stack & rationale

To make this game, I used a combination of Node, React, Socket.io, and webpack. Node handles the serving of static js, css, and html files, which are transpiled and compiled by webpack. Socket.io manages the connection between players and emitting events React uses to manage the state of the UI.

The entry point for the game code is src/js/main.js, which iniitalizes the React component. The heart of the game code is in src/js/components/game.js for the UI and ./socketServer.js for the back end.

Because the game is for two players, it also has potential application in the online dating world, as a kind of ice breaker for potential matches. It provides an additional way to interact online that isn't just browsing information or chatting, which is important when trying to learn who a person is. I also love wordplay, and the idea of an online-dating nim-game called matchsticks was too clever not to make.


running the game

Node developers will already know the drill:

git clone https://github.com/ellismarkf/matchsticks.git

then

cd matchsticks
npm install
npm start

and finally, navigate to localhost:5000 in your browser. Et voila!

This is a 2-player, socket-based game, so you'll need a friend to play with in another tab on your machine, or if you're both on the same network, on another computer, in which case the second player should navigate to whatever IP address your machine uses, eg 192.186.1.80:5000. Just make sure they're using the right port (5000, by default).

Alternatively, you can go to matchsticks-nim.herokuapp.com, and play online with a friend. The same principle applies: both parties must visit the url at the same time before they can start a game.


playing the game

Once two players have arrived at the game, one player should click the p1 button to initialize the game. The game starts after the second player has joined the game by clicking p2, and immediately lets player 1 take as many sticks from one row as desired.

If a player takes all the sticks from one row, her turn is over, and the other player is free to take objects. At any point after a player has taken a stick, they are free to end their turn.

The game is over when one player takes the last remaining stick.

matchsticks-nim-react's People

Contributors

ellismarkf avatar

Watchers

 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.