Connect-Four
Task
You need to create a client (bot) which will be playing Connect Four with other bots. Manual execution of moves is NOT allowed. Manual connection to a socket and specific channel is allowed though. Programming language doesn't matter.
Flow
-
Open TCP socket connection to platinum.edu.pl on port 4242
-
Send command
NAME your_nick_name
. It will be displayed in the statistics. You will receiveSUCCESS
response -
Send command
JOIN channel_name
, wherechannel_name
is an arbitrary String. It's used to connect 2 opponents to a single channel to play with each other. As a response, you will receive eitherSUCCESS
orCHANNEL_IS_FULL
, if the corresponding channel already has 2 players in game. You can't join other channel after this or during the game. -
When both players are connected to the same channel, they will receive Message
NEW_GAME
. This informs you, that you should reset your game board state. You can receive this message at any time, for example on a new round or when your opponent is changed -
One of the players will receive
YOUR_MOVE
Message. After this you can send the command to put a disc into some column -
This player now should send a command
PUT column_index
, wherecolumn_index
is an integer from 0 to 6. He can do this ONLY after receivingYOUR_MOVE
command -
Opponent will receive command
PUT column_index
, which is reflecting previous player's move. This means, that you should update your local game board state -
After this, player will receive
YOUR_MOVE
Message. If game is not finished, go to step 5 -
If someone wins, this player receives
YOU_WON
. Opponent receivesYOU_LOST
. If the board is full and there's no winner, every player will receiveDRAW
. You should NOT disconnect from the socket here -
There will be 4 rounds with the same opponent, every player will receive
NEW_GAME
message, look at step 4. Colors of the players will be swapped, to allow other player make first move -
At the very end, both players will be disconnected from the socket automatically
Protocol
-
Commands are NOT case sensitive
-
Every Command must end with
\n
-
Server doesn't send the current state of the board, you should store it yourself. It only sends you the moves of your opponent (
PUT column_index
) -
Game board is 6x7 (6 rows, 7 columns)
-
Column index is an integer from 0 to 6
-
Messages sent from server can be 1 or 2 words long. Each one ends with
\n
. Example:YOUR_MOVE
- 1 word.PUT 5
- 2 words. -
If you are trying to execute some illegal command, you will receive a corresponding error (see error list). Don't try to cheat in game (making double moves, making a move before receiving a signal, sending invalid index). You will be punished (auto lose) and disconnected from the socket in this case.
-
Errors format is
Error ERROR_NAME
Testing
If you need to test your client, send NAME TEST
command, run two instances of your bot and JOIN
to some channel with both of them.
Errors list
-
INVALID_COMMAND
-
CHANNEL_IS_FULL
-
INVALID_COLUMN
-
COLUMN_IS_FULL
-
NOT_JOINED_TO_CHANNEL
-
WRONG_COLUMN_FORMAT
-
NOT_YOUR_TURN
Messages list
-
YOUR_MOVE
-
YOU_WON
-
YOU_LOST
-
NEW_GAME
-
DRAW
-
SUCCESS