Giter Site home page Giter Site logo

connecti4n's Introduction

ConnectI4n

A simple Connect 4 server and client for our Network Principles course.

Usage

On a second computer or all on localhost, run the server using any any installation of python 3 that includes the standard libraries. Then you can run the client and give the IP address of the server, then you start playing.

Credits

Ethan Martin for the Server

Stefano Coronado for the client

Protocol

Each message passed between a client and a server must have at least three components, separated by a space. First, C4N to signify that this is a ConnectI4n message. Next, a version number. Finally, the message type. Available message types are determined by the protocol version. Some message types may have additional data following the header, separated by a newline character. The format of this data is expected to be known to the client/server.

Message Types

Version 1.0

Message Type Data Length Direction
ERROR 1 any
STOP none any
START none client -> server
MOVE 1 client -> server
BOARD variable server -> client
RESULT 1 server -> client

ERROR

Error messages can be sent from either the client or the server at any time to indicate that something has gone wrong. A single number is allowed as data, signifying the error code. Available codes are as follows:

Error Description
1 Invalid message
2 (server -> client only) Invalid move
3 (server -> client only) Server full
99 Unknown error

STOP

The client or the server can cleanly attempt to close the game early using this message. A client or server need not respond to this message, and may terminate the connection immediately.

START

A client wishing to begin a new game opens a connection and sends this message. If the server is full, it will respond with error code 3 and a game will not begin. Otherwise the server will respond with the initial board state.

MOVE

When it is the player's turn, the client should prompt the user for the column in which they would like to place a token, and send the integer index of that column as the data for this message. If it is not possible to place a token where the player has chosen, the server will respond with error code 2. A responsible client should however check the validity of the move before sending to the server. If the move is valid, the server will respond with two BOARD messages: one after the player's move, and another after the AI's move.

BOARD

The server uses this message to communicate the current state of the game board to the client. It will have at minimum two integer parameters, one with the number of columns, and another with the number of rows. The current value for each space on the board will follow in sequence row by row, where 0 is an empty space, 1 is a player token, and 2 is an AI token:

RESULT

When the game has ended as a result of normal play, the server sends this message to inform the client of the winner. The data will be a 1 if the player wins, and a 2 if the AI wins. At this point the connection will be terminated.

connecti4n's People

Contributors

scoronado12 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.