#include <Keypad.h>
#include "MicroMaxChess.h"
const uint8_t ROWS = 4;
const uint8_t COLS = 4;
char keys[ROWS][COLS] = {
{ '1', '2', '3', 'a' },
{ '4', '5', '6', 'b' },
{ '7', '8', 'c', 'd' },
{ 'e', 'f', 'g', 'h' }
};
uint8_t colPins[COLS] = { 5, 4, 3, 2 }; // Pins connected to C1, C2, C3, C4
uint8_t rowPins[ROWS] = { 12, 11, 10, 9 }; // Pins connected to R1, R2, R3, R4
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
char move[5];
MicroMaxChess chess;
char readKey() {
while (true) {
char key = keypad.getKey();
if (key != NO_KEY)
return key;
}
}
char *read_user_move() {
for (int i = 0; i < 4; ++i) {
move[i] = readKey();
Serial.print(move[i]);
}
move[4] = 0;
return move;
}
void setup() {
Serial.begin(9600);
Serial.println("MicroMax Chess - engine created by H.G. Muller");
}
void loop() {
Serial.println();
Serial.print(chess.moveNumber());
Serial.print(": ");
if (!chess.move(read_user_move())) {
Serial.println(" ** Illegal move **");
return;
}
Serial.print(" - ");
char *computer_move = chess.move();
Serial.println(computer_move);
chess.move(computer_move);
chess.printBoard(Serial);
}