Skip to content

LucasAstley/Connect-4-Challenge-Go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ymmersion - Connect 4 Challenge go

This is the latest ymmersion exercice, this challenge consists of creating a console connect 4 in Go.

Instructions

$ go run . 
|   |   |   |   |   |   |   |
-----------------------------
|   |   |   |   |   |   |   |
-----------------------------
|   |   |   |   |   |   |   |
-----------------------------
|   |   | X |   |   |   |   |
-----------------------------
|   |   | O | X |   |   |   |
-----------------------------
|   | X | X | O | O |   |   |
-----------------------------
| O | X | O | X | O |   |   |

Player X's turn. Choose column (0-7):
  • Check for wins after each move: The game should verify if there are four connected pieces in any direction—vertical, horizontal, or diagonal.
  • Continue the game until a player wins or all spaces are filled, resulting in a draw.
  • Comment your code to explain the implementation of game mechanics and logic decisions. Be careful to put relevant comments!
  • Structure your code to handle game state management, user input, and display output cleanly and efficiently.

Bonus tasks

  • Include error handling for invalid inputs such as entering non-numeric values, choosing columns that are out of bounds, or selecting columns that are already full.
  • Enhance the game by adding colors to the discs (X and O).
  • Allow the players to play multiple rounds without restarting the program.
  • Improve the terminal UI to make it more user-friendly, e.g., by clearing the screen before displaying the board.

My structure

├── grid
│   ├── gridCreator.go
│   ├── gridPrinter.go
│   ├── isGridFull.go
│   └── winChecker.go
├── players
│   ├── nextPlayer.go
│   ├── pieceInsert.go
│   └── playAgain.go
├── main.go
├── technical_structure_and_logic.txt
└── README.md

As explained in technical_structure_and_logic my playing grid is represented by a bi-dimensional array :

schema

I also use aurora package to print elements with color in the console.

Demo

Gameplay Full column error Bad input error
demo-gif column-error-gif input-error-gif

About

Console connect 4 in Golang

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages