กลับไปหน้ารวมไฟล์
arduino-connect-4-game-human-vs-microcontroller-34cf6c-en.md

Connect Four is a two-player strategy game in which the players take turns dropping colored discs into a vertical grid. The objective of the game is to connect four of one's own discs of the same color vertically, horizontally, or diagonally before your opponent does.

In one of my previous videos I described a way to make such a game on a TFT touch screen. This time I will explain to you how to make a Connect4 game on an 8 x 8 pixel matrix with 5050 type LEDs with a built-in WS2812B chip.

Also now we have two game modes, player vs player and player vs microcontroller. You can find the original code at AZdelivery :

, and then this code was reworked by Mr. Küster adding the ability to play against a microcontroller. I also added simple sounds with help of "NewTone" library , so the game now is even more interesting.

Otherwise, the device is very simple to build and contains several components:

- Arduino Nano microcontroller

- 8x8 RGB matrix with WS2812 led chips

- Three buttons,

- and Buzzer

Also for the led matrix I made a dedicated grid on a 3D Printer for a better visual impression. Tracing paper is placed on the grid for light diffusion, and then a protective transparent film.

Let's see how the game works in reality:

After starting the device, with the left button we select player vs player mode, while with the right button player vs microcontroller. In Player vs. Player, the starting color will be changed with each new game, and in Player vs. Microcontroller, the player always has red and begins the first game. After that, the loser always begins. First we will start a game player against the microcontroller, which is indicated by a continuous higher tone. Player is in red, and start first. At the end, if the microcontroller wins, display shows a smiling figure, and if Player win, then figure is sad.

The next mod is player vs player. This mode is indicated by a continuous lower tone. After one of the players wins, a line is indicated by three short flashes followed by a high-pitched sound, and then the entire screen lights up with the winner's color.

The device is built into a box from a my previous project , which is made of 3 and 5 mm PVC board, lined with self-adhesive colored wallpaper.

EXPANDED TECHNICAL DETAILS

Strategic AI Game Interaction

This project implements the classic "Connect 4" logic on a digital interface, featuring a "Smart" AI opponent that plays against the user.

  • Minimax Game-Tree Implementation: The Arduino runs a simplified Minimax algorithm. For every turn, the firmware "Looks Ahead" 3-5 moves to evaluate which column provides the highest probability of a "Four-in-a-Row" victory.
  • Interactive LED Gameboard: Uses an 8x8 LED Matrix or a custom 7x6 grid of NeoPixels. The Arduino manages the "Falling Animation" of the game pieces and indicates the winner with a flashing sequence.

Interaction

  • Input Matrix Scanning: The user selects their move using a physical rotary encoder or a series of buttons, with the Arduino providing auditory cues for every turn.

ข้อมูล Frontmatter ดั้งเดิม

title: "Arduino Connect 4 Game Human vs Microcontroller"
description: "Connect4 game on an 8 x 8 pixel matrix with 5050 type LEDs"
author: "mircemk"
category: "Gadgets, Games & Toys"
tags:
  - "Games"
  - "Audio"
views: 2355
likes: 1
price: 2450
difficulty: "Easy"
components:
  - "1x Piezo Buzzer"
  - "1x 8*8 led matrix"
  - "1x Push Button"
  - "1x Soldering kit"
  - "1x Arduino Nano"
tools: []
apps:
  - "1x Arduino IDE"
downloadableFiles: []
documentationLinks: []
passwordHash: "b6eb6d16f9fd7bbf9eb7473e854ee469c272f240fd7312228cfb4b7d0610717b"
encryptedPayload: "U2FsdGVkX19V4VEtHCm1CkW/cj2ZaBG5UiLL9gQaSbUJMNeGyAec4p7jOEqc9EfagG7B2jvdW5y1Z/aw0JCHbJpVxriqLgR7zbiCL1G8Sl8="
seoDescription: "Build an Arduino Connect4 game with an 8 x 8 pixel matrix and 5050 type LEDs. Play Human vs Microcontroller in this DIY project."
videoLinks:
  - "https://youtu.be/4c123jpPZYk"
heroImage: "https://cdn.jsdelivr.net/gh/bigboxthailand/arduino-assets@main/images/projects/arduino-connect-4-game-human-vs-microcontroller-34cf6c_cover.jpg"
lang: "en"