5 kyu

Connect 4

87 of 1,578adrian.eyre

Description:

Introduction

We all love to play games especially as children. I have fond memories playing Connect 4 with my brother so decided to create this Kata based on the classic game. Connect 4 is known as several names such as “Four in a Row” and “Captain’s Mistress" but was made popular by Hasbro MB Games
Connect 4

Task

The game consists of a grid (7 columns and 6 rows) and two players that take turns to drop their discs. The pieces fall straight down, occupying the next available space within the column. The objective of the game is to be the first to form a horizontal, vertical, or diagonal line of four of one's own discs.

Your task is to create a Class called Connect4 that has a method called play which takes one argument for the column where the player is going to place their disc.

Rules

If a player successfully has 4 discs horizontally, vertically or diagonally then you should return "Player n wins!” where n is the current player either 1 or 2.

If a player attempts to place a disc in a column that is full then you should return ”Column full!” and the next move must be taken by the same player.

If the game has been won by a player, any following moves should return ”Game has finished!”.

Any other move should return ”Player n has a turn” where n is the current player either 1 or 2.
 
Player 1 starts the game every time and alternates with player 2.

The columns are numbered 0-6 left to right.

Good luck and enjoy!

Kata Series

If you enjoyed this, then please try one of my other Katas. Any feedback, translations and grading of beta Katas are greatly appreciated. Thank you.

Rank Maze Runner

Rank Scooby Doo Puzzle

Rank Driving License

Rank Connect 4

Rank Vending Machine

Rank Snakes and Ladders

Rank Mastermind

Rank Guess Who?

Rank Am I safe to drive?

Rank Mexican Wave

Rank Pigs in a Pen

Rank Hungry Hippos

Rank Plenty of Fish in the Pond

Rank Fruit Machine

Rank Car Park Escape

Arrays
Fundamentals

Stats:

CreatedJan 3, 2017
PublishedJan 3, 2017
Warriors Trained9026
Total Skips1958
Total Code Submissions23539
Total Times Completed1578
Ruby Completions87
JavaScript Completions392
Python Completions633
C# Completions204
TypeScript Completions124
PHP Completions84
VB Completions5
Java Completions88
Total Stars449
% of votes with a positive feedback rating94% of 352
Total "Very Satisfied" Votes315
Total "Somewhat Satisfied" Votes34
Total "Not Satisfied" Votes3
Total Rank Assessments10
Average Assessed Rank
5 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
6 kyu
Ad
Contributors
  • adrian.eyre Avatar
  • tachyonlabs Avatar
  • Blind4Basics Avatar
  • hobovsky Avatar
  • Agent00K Avatar
Ad