kk logo

Vier gewinnt (englisch: Connect Four oder Captain’s mistress) ist ein Zweipersonen-Strategiespiel mit dem Ziel, als Erster vier der eigenen Spielsteine in eine Linie zu bringen.

 Link zum Youtube Video: https://youtu.be/jYuhiBzRN30

Das Spiel wird auf einer 8x8 LED NeoPixel (bzw. ws2812b Chip) gespielt. Wobei dir oberste Reihe nur zur Auswahl der Reihe und nicht als Spielfeld zählt. Über den Poti und den grünen Taster werden die „Spielsteine“ in Form roter und grüner LEDs gesetzt. Gewinner ist, wer vier oder mehr seiner Spielsteine in eine waagerechte, senkrechte oder diagonale Linie bringt. Das Spiel endet unentschieden, wenn die LED Matrix gefüllt ist, ohne dass ein Spieler eine Viererlinie gebildet hat.

Für das Spiel benötigst du relativ wenig Hardware

  • 8x8 LED Neopixel Matrix
    • VCC/GND und digitaler PIN 9
    • Externe Spannung (rot/schwarz) 5 VDC
  • 3 Taster Modul oder andere 3 Taster (Pin ggf. ändern)
    • VCC/GND und analoger Pin A1
  • Dreh- Potenziometer (Poti)
    • VCC/GND und analoger Pin A0

Das Programm habe ich mit Ardublock erstellt, unten gibt es aber auch noch das Arduino DIE Programm zu kopieren und einfügen.

Strategie und Taktik

Als Faustregel gilt, dass Spielsteine in der Mitte des Spielbretts mehr Wert haben als Spielsteine am Rand des Spielbretts, da es für sie mehr Möglichkeiten gibt, an Viererlinien beteiligt zu sein (und somit auch die Möglichkeiten des Gegners einschränken). Gute Spieler versuchen, kurzfristig drei Spielsteine in eine Linie zu bringen und gleichzeitig den Gegner daran zu hindern, in eine bestimmte Spalte zu setzen. Zum Ende hin wird das Spiel oft zu einem komplexen Auszählspiel; beide Spieler versuchen zu gewinnen, indem sie den Gegner zwingen, in eine bestimmte Spalte zu setzen. Für den Spieler am Zug ist dabei die Regel hilfreich, dass immer eine gerade Zahl von Spielsteinen gesetzt wird, bis er selbst wieder am Zug ist.

Ardublock als .Zip zm Download. 

Arduino Code:

#include <Adafruit_NeoPixel.h>

Adafruit_NeoPixel strip_pin9 = Adafruit_NeoPixel(64,9, NEO_GRB + NEO_KHZ800);
int matrix[64] = {0};
int lux = 6;
int poti = 0;
byte spiel = 0;
void Unterprogramm1();

void Unterprogramm5();

int reset = 0;
void Unterprogramm0();

int stellen_1 = 0;
int stellen_3 = 16;
int stellen_5 = 32;
int stellen_7 = 48;
int stellen_2 = 15;
int stellen_4 = 31;
int stellen_6 = 47;
int stellen_8 = 63;
void Unterprogramm4();

int count = 0;
void Unterprogramm2();

void Unterprogramm3();

void setup() {
strip_pin9.begin();
strip_pin9.show();
lux = 6;

Unterprogramm0();

}

void loop() {
if (( ( analogRead(1) > 300 ) && ( analogRead(1) < 550 ) )) {

if (( lux < 30 )) {

lux = ( lux + 2 );
}
else {
lux = ( lux + 20 );
}
delay( 130 );
if (( lux > 220 )) {

lux = 0;
delay( 1000 );
}
}
poti = map ( analogRead(0) , 0 , 1023 , 0 , 800 ) ;
while ( ( ( analogRead(1) > 50 ) && ( analogRead(1) < 300 ) ) ) {
while ( ( ( analogRead(1) > 50 ) && ( analogRead(1) < 300 ) ) ) {
delay( 10 );
}
Unterprogramm3();
Unterprogramm4();
if (( spiel == 2 )) {

spiel = 0;
}
spiel = ( spiel + 1 );
}
if (( spiel == 1 )) {

Unterprogramm1();
}
if (( spiel == 2 )) {

Unterprogramm2();
}
if (( analogRead(1) > 570 )) {

Unterprogramm5();
}
}

//auswahl led rot
void Unterprogramm1() {
if (( ( poti >= 0 ) && ( poti < 100 ) )) {

strip_pin9.setPixelColor(7,255 ,0 ,0 );
strip_pin9.setPixelColor(8,0 ,0 ,0 );
strip_pin9.setBrightness(lux);
strip_pin9.show();
}
if (( ( poti > 100 ) && ( poti < 200 ) )) {

strip_pin9.setPixelColor(8,255 ,0 ,0 );
strip_pin9.setPixelColor(7,0 ,0 ,0 );
strip_pin9.setPixelColor(23,0 ,0 ,0 );
strip_pin9.setBrightness(lux);
strip_pin9.show();
}
if (( ( poti > 200 ) && ( poti < 300 ) )) {

strip_pin9.setPixelColor(23,255 ,0 ,0 );
strip_pin9.setPixelColor(8,0 ,0 ,0 );
strip_pin9.setPixelColor(24,0 ,0 ,0 );
strip_pin9.setBrightness(lux);
strip_pin9.show();
}
if (( ( poti > 300 ) && ( poti < 400 ) )) {

strip_pin9.setPixelColor(24,255 ,0 ,0 );
strip_pin9.setPixelColor(23,0 ,0 ,0 );
strip_pin9.setPixelColor(39,0 ,0 ,0 );
strip_pin9.setBrightness(lux);
strip_pin9.show();
}
if (( ( poti > 400 ) && ( poti < 500 ) )) {

strip_pin9.setPixelColor(39,255 ,0 ,0 );
strip_pin9.setPixelColor(24,0 ,0 ,0 );
strip_pin9.setPixelColor(40,0 ,0 ,0 );
strip_pin9.setBrightness(lux);
strip_pin9.show();
}
if (( ( poti > 500 ) && ( poti < 600 ) )) {

strip_pin9.setPixelColor(40,255 ,0 ,0 );
strip_pin9.setPixelColor(39,0 ,0 ,0 );
strip_pin9.setPixelColor(55,0 ,0 ,0 );
strip_pin9.setBrightness(lux);
strip_pin9.show();
}
if (( ( poti > 600 ) && ( poti < 700 ) )) {

strip_pin9.setPixelColor(55,255 ,0 ,0 );
strip_pin9.setPixelColor(40,0 ,0 ,0 );
strip_pin9.setPixelColor(56,0 ,0 ,0 );
strip_pin9.setBrightness(lux);
strip_pin9.show();
}
if (( ( poti > 700 ) && ( poti < 800 ) )) {

strip_pin9.setPixelColor(56,255 ,0 ,0 );
strip_pin9.setPixelColor(55,0 ,0 ,0 );
strip_pin9.setBrightness(lux);
strip_pin9.show();
}
}

//reset
void Unterprogramm5() {
delay( 200 );
reset = 0;
for (int i = 0; i < 64; i++) {
matrix[reset] = 0;
strip_pin9.setPixelColor(reset,0 ,0 ,0 );
reset = ( reset + 1 );
}
strip_pin9.setBrightness(lux);
strip_pin9.show();
Unterprogramm0();
}

//setupup
void Unterprogramm0() {
spiel = 2;
matrix[0] = 1;
matrix[15] = 1;
matrix[16] = 1;
matrix[31] = 1;
matrix[32] = 1;
matrix[47] = 1;
matrix[48] = 1;
matrix[63] = 1;
stellen_1 = 0;
stellen_3 = 16;
stellen_5 = 32;
stellen_7 = 48;
stellen_2 = 15;
stellen_4 = 31;
stellen_6 = 47;
stellen_8 = 63;
}

//LED setzen ungerade
void Unterprogramm4() {
if (( ( stellen_2 > 7 ) && ( ( poti > 100 ) && ( poti < 200 ) ) )) {

count = 0;
for (int i = 0; i < 8; i++) {
if (( 0 != matrix[count] )) {

if (( spiel == 1 )) {

strip_pin9.setPixelColor(stellen_2,255 ,0 ,0 );
strip_pin9.setBrightness(lux);
strip_pin9.show();
}
if (( spiel == 2 )) {

strip_pin9.setPixelColor(stellen_2,0 ,0 ,255 );
strip_pin9.setBrightness(lux);
strip_pin9.show();
}
}
count = ( count + 1 );
}
stellen_2 = ( stellen_2 - 1 );
}
if (( ( stellen_4 > 23 ) && ( ( poti > 300 ) && ( poti < 400 ) ) )) {

count = 0;
for (int i = 0; i < 8; i++) {
if (( 0 != matrix[count] )) {

if (( spiel == 1 )) {

strip_pin9.setPixelColor(stellen_4,255 ,0 ,0 );
strip_pin9.setBrightness(lux);
strip_pin9.show();
}
if (( spiel == 2 )) {

strip_pin9.setPixelColor(stellen_4,0 ,0 ,255 );
strip_pin9.setBrightness(lux);
strip_pin9.show();
}
}
count = ( count + 1 );
}
stellen_4 = ( stellen_4 - 1 );
}
if (( ( stellen_6 > 39 ) && ( ( poti > 500 ) && ( poti < 600 ) ) )) {

count = 0;
for (int i = 0; i < 8; i++) {
if (( 0 != matrix[count] )) {

if (( spiel == 1 )) {

strip_pin9.setPixelColor(stellen_6,255 ,0 ,0 );
strip_pin9.setBrightness(lux);
strip_pin9.show();
}
if (( spiel == 2 )) {

strip_pin9.setPixelColor(stellen_6,0 ,0 ,255 );
strip_pin9.setBrightness(lux);
strip_pin9.show();
}
}
count = ( count + 1 );
}
stellen_6 = ( stellen_6 - 1 );
}
if (( ( stellen_8 > 55 ) && ( ( poti > 700 ) && ( poti < 810 ) ) )) {

count = 0;
for (int i = 0; i < 8; i++) {
if (( 0 != matrix[count] )) {

if (( spiel == 1 )) {

strip_pin9.setPixelColor(stellen_8,255 ,0 ,0 );
strip_pin9.setBrightness(lux);
strip_pin9.show();
}
if (( spiel == 2 )) {

strip_pin9.setPixelColor(stellen_8,0 ,0 ,255 );
strip_pin9.setBrightness(lux);
strip_pin9.show();
}
}
count = ( count + 1 );
}
stellen_8 = ( stellen_8 - 1 );
}
}

//auswahl led blau
void Unterprogramm2() {
if (( ( poti >= 0 ) && ( poti < 100 ) )) {

strip_pin9.setPixelColor(7,0 ,0 ,255 );
strip_pin9.setPixelColor(8,0 ,0 ,0 );
strip_pin9.setBrightness(lux);
strip_pin9.show();
}
if (( ( poti > 100 ) && ( poti < 200 ) )) {

strip_pin9.setPixelColor(8,0 ,0 ,255 );
strip_pin9.setPixelColor(7,0 ,0 ,0 );
strip_pin9.setPixelColor(23,0 ,0 ,0 );
strip_pin9.setBrightness(lux);
strip_pin9.show();
}
if (( ( poti > 200 ) && ( poti < 300 ) )) {

strip_pin9.setPixelColor(23,0 ,0 ,255 );
strip_pin9.setPixelColor(8,0 ,0 ,0 );
strip_pin9.setPixelColor(24,0 ,0 ,0 );
strip_pin9.setBrightness(lux);
strip_pin9.show();
}
if (( ( poti > 300 ) && ( poti < 400 ) )) {

strip_pin9.setPixelColor(24,0 ,0 ,255 );
strip_pin9.setPixelColor(23,0 ,0 ,0 );
strip_pin9.setPixelColor(39,0 ,0 ,0 );
strip_pin9.setBrightness(lux);
strip_pin9.show();
}
if (( ( poti > 400 ) && ( poti < 500 ) )) {

strip_pin9.setPixelColor(39,0 ,0 ,255 );
strip_pin9.setPixelColor(24,0 ,0 ,0 );
strip_pin9.setPixelColor(40,0 ,0 ,0 );
strip_pin9.setBrightness(lux);
strip_pin9.show();
}
if (( ( poti > 500 ) && ( poti < 600 ) )) {

strip_pin9.setPixelColor(40,0 ,0 ,255 );
strip_pin9.setPixelColor(39,0 ,0 ,0 );
strip_pin9.setPixelColor(55,0 ,0 ,0 );
strip_pin9.setBrightness(lux);
strip_pin9.show();
}
if (( ( poti > 600 ) && ( poti < 700 ) )) {

strip_pin9.setPixelColor(55,0 ,0 ,255 );
strip_pin9.setPixelColor(40,0 ,0 ,0 );
strip_pin9.setPixelColor(56,0 ,0 ,0 );
strip_pin9.setBrightness(lux);
strip_pin9.show();
}
if (( ( poti > 700 ) && ( poti < 800 ) )) {

strip_pin9.setPixelColor(56,0 ,0 ,255 );
strip_pin9.setPixelColor(55,0 ,0 ,0 );
strip_pin9.setBrightness(lux);
strip_pin9.show();
}
}

//LED setzen gerade
void Unterprogramm3() {
if (( ( stellen_1 < 7 ) && ( ( poti >= 0 ) && ( poti < 100 ) ) )) {

count = 0;
for (int i = 0; i < 8; i++) {
if (( 0 != matrix[count] )) {

if (( spiel == 1 )) {

strip_pin9.setPixelColor(stellen_1,255 ,0 ,0 );
strip_pin9.setBrightness(lux);
strip_pin9.show();
}
if (( spiel == 2 )) {

strip_pin9.setPixelColor(stellen_1,0 ,0 ,255 );
strip_pin9.setBrightness(lux);
strip_pin9.show();
}
}
count = ( count + 1 );
}
stellen_1 = ( stellen_1 + 1 );
}
if (( ( stellen_3 < 23 ) && ( ( poti > 200 ) && ( poti < 300 ) ) )) {

count = 0;
for (int i = 0; i < 8; i++) {
if (( 0 != matrix[count] )) {

if (( spiel == 1 )) {

strip_pin9.setPixelColor(stellen_3,255 ,0 ,0 );
strip_pin9.setBrightness(lux);
strip_pin9.show();
}
if (( spiel == 2 )) {

strip_pin9.setPixelColor(stellen_3,0 ,0 ,255 );
strip_pin9.setBrightness(lux);
strip_pin9.show();
}
}
count = ( count + 1 );
}
stellen_3 = ( stellen_3 + 1 );
}
if (( ( stellen_5 < 39 ) && ( ( poti > 400 ) && ( poti < 500 ) ) )) {

count = 0;
for (int i = 0; i < 8; i++) {
if (( 0 != matrix[count] )) {

if (( spiel == 1 )) {

strip_pin9.setPixelColor(stellen_5,255 ,0 ,0 );
strip_pin9.setBrightness(lux);
strip_pin9.show();
}
if (( spiel == 2 )) {

strip_pin9.setPixelColor(stellen_5,0 ,0 ,255 );
strip_pin9.setBrightness(lux);
strip_pin9.show();
}
}
count = ( count + 1 );
}
stellen_5 = ( stellen_5 + 1 );
}
if (( ( stellen_7 < 55 ) && ( ( poti > 600 ) && ( poti < 700 ) ) )) {

count = 0;
for (int i = 0; i < 8; i++) {
if (( 0 != matrix[count] )) {

if (( spiel == 1 )) {

strip_pin9.setPixelColor(stellen_7,255 ,0 ,0 );
strip_pin9.setBrightness(lux);
strip_pin9.show();
}
if (( spiel == 2 )) {

strip_pin9.setPixelColor(stellen_7,0 ,0 ,255 );
strip_pin9.setBrightness(lux);
strip_pin9.show();
}
}
count = ( count + 1 );
}
stellen_7 = ( stellen_7 + 1 );
}
}

Ronnie

schwäbischer tüftler und bastler, kraftsportler, ADHS power, 43 Jahre, 1 Frau, 5 Kinder und 1003 Ideen. 

ronnie berzins at mee

...

Denn du bist ein Unikat, einzig in deiner Art
Wir alle ecken an so wie in ein Quadrat
Du bist ein Unikat, du bist so wie du bist
Egal, was sie labern, wir geben kein'n Fick.

SDP, Unikat