#include <U8g2lib.h>
#define xa A0
#define xb A1
U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);
int coordinates[8][8][2] = {
{{2, 7}, {10, 7}, {18, 7}, {26, 7}, {34, 7}, {42, 7}, {50, 7}, {58, 7}},
{{2, 15}, {10, 15}, {18, 15}, {26, 15}, {34, 15}, {42, 15}, {50, 15}, {58, 15}},
{{2, 23}, {10, 23}, {18, 23}, {26, 23}, {34, 23}, {42, 23}, {50, 23}, {58, 23}},
{{2, 31}, {10, 31}, {18, 31}, {26, 31}, {34, 31}, {42, 31}, {50, 31}, {58, 31}},
{{2, 39}, {10, 39}, {18, 39}, {26, 39}, {34, 39}, {42, 39}, {50, 39}, {58, 39}},
{{2, 47}, {10, 47}, {18, 47}, {26, 47}, {34, 47}, {42, 47}, {50, 47}, {58, 47}},
{{2, 55}, {10, 55}, {18, 55}, {26, 55}, {34, 55}, {42, 55}, {50, 55}, {58, 55}},
{{2, 63}, {10, 63}, {18, 63}, {26, 63}, {34, 63}, {42, 63}, {50, 63}, {58, 63}}
};
int coordinateee[8][8][2] = {
{{1, 1}, {9, 1}, {17, 1}, {25, 1}, {33, 1}, {41, 1}, {49, 1}, {57, 1}},
{{1, 9}, {9, 9}, {17, 9}, {25, 9}, {33, 9}, {41, 9}, {49, 9}, {57, 9}},
{{1, 17}, {9, 17}, {17, 17}, {25, 17}, {33, 17}, {41, 17}, {49, 17}, {57, 17}},
{{1, 25}, {9, 25}, {17, 25}, {25, 25}, {33, 25}, {41, 25}, {49, 25}, {57, 25}},
{{1, 33}, {9, 33}, {17, 33}, {25, 33}, {33, 33}, {41, 33}, {49, 33}, {57, 33}},
{{1, 41}, {9, 41}, {17, 41}, {25, 41}, {33, 41}, {41, 41}, {49, 41}, {57, 41}},
{{1, 49}, {9, 49}, {17, 49}, {25, 49}, {33, 49}, {41, 49}, {49, 49}, {57, 49}},
{{1, 57}, {9, 57}, {17, 57}, {25, 57}, {33, 57}, {41, 57}, {49, 57}, {57, 57}}
};
void setup() {
u8g2.begin();
pinMode(xa, INPUT);
pinMode(xb, INPUT);
}
void loop() {
int xa1 = analogRead(xa);
int x6 = map(xa1, 0, 1023, 0, 7);
int xb1 = analogRead(xb);
int y6 = map(xb1, 0, 1023, 0, 7);
u8g2.clearBuffer();
u8g2.setFontMode(1);
u8g2.setBitmapMode(1);
u8g2.drawBox(0, 0, 8, 8);
u8g2.drawBox(16, 0, 8, 8);
u8g2.drawBox(32, 0, 8, 8);
u8g2.drawBox(48, 0, 8, 8);
u8g2.drawBox(8, 8, 8, 8);
u8g2.drawBox(24, 8, 8, 8);
u8g2.drawBox(40, 8, 8, 8);
u8g2.drawBox(56, 8, 8, 8);
u8g2.drawBox(0, 16, 8, 8);
u8g2.drawBox(16, 16, 8, 8);
u8g2.drawBox(32, 16, 8, 8);
u8g2.drawBox(48, 16, 8, 8);
u8g2.drawBox(8, 24, 8, 8);
u8g2.drawBox(24, 24, 8, 8);
u8g2.drawBox(40, 24, 8, 8);
u8g2.drawBox(56, 24, 8, 8);
u8g2.drawBox(0, 32, 8, 8);
u8g2.drawBox(16, 32, 8, 8);
u8g2.drawBox(32, 32, 8, 8);
u8g2.drawBox(48, 32, 8, 8);
u8g2.drawBox(8, 40, 8, 8);
u8g2.drawBox(24, 40, 8, 8);
u8g2.drawBox(40, 40, 8, 8);
u8g2.drawBox(56, 40, 8, 8);
u8g2.drawBox(0, 48, 8, 8);
u8g2.drawBox(16, 48, 8, 8);
u8g2.drawBox(32, 48, 8, 8);
u8g2.drawBox(48, 48, 8, 8);
u8g2.drawBox(8, 56, 8, 8);
u8g2.drawBox(24, 56, 8, 8);
u8g2.drawBox(40, 56, 8, 8);
u8g2.drawBox(56, 56, 8, 8);
u8g2.drawLine(64, 0, 64, 64);
Drawing_Func() ;
u8g2.setDrawColor(1);
u8g2.setFont(u8g2_font_5x7_tr);
u8g2.drawStr(67, 7, "K,O =King");
u8g2.drawStr(67, 15, "P,U =Pawn");
u8g2.drawStr(67, 31, "F,Q =Queen");
u8g2.drawStr(67, 39, "C,B =Bishop");
u8g2.drawStr(67, 47, "I,H =Knight");
u8g2.drawStr(67, 23, "S,R =Rook");
u8g2.setFont(u8g2_font_4x6_tr);
u8g2.drawStr(67, 62, "U,S,I,C,F,O ");
u8g2.drawStr(67, 55, "P,R,H,B,K,Q");
u8g2.drawBox(113, 50, 8, 5);
u8g2.drawFrame(113, 57, 8, 5);
u8g2.sendBuffer();
}
void Drawing_Func() {
u8g2.setDrawColor(2);
u8g2.setFont(u8g2_font_5x8_tr);
u8g2.drawStr(coordinates[0][4][0], coordinates[0][4][1], "Q");
u8g2.drawStr(coordinates[0][6][0], coordinates[0][6][1], "H");
u8g2.drawStr(coordinates[0][1][0], coordinates[0][1][1], "H");
u8g2.drawStr(coordinates[0][0][0], coordinates[0][0][1], "R");
u8g2.drawStr(coordinates[0][7][0], coordinates[0][7][1], "R");
u8g2.drawStr(coordinates[0][2][0], coordinates[0][2][1], "B");
u8g2.drawStr(coordinates[0][5][0], coordinates[0][5][1], "B");
u8g2.drawStr(coordinates[0][3][0], coordinates[0][3][1], "K");
u8g2.drawStr(coordinates[1][0][0], coordinates[1][0][1], "P");
u8g2.drawStr(coordinates[1][1][0], coordinates[1][1][1], "P");
u8g2.drawStr(coordinates[1][2][0], coordinates[1][2][1], "P");
u8g2.drawStr(coordinates[1][3][0], coordinates[1][3][1], "P");
u8g2.drawStr(coordinates[1][4][0], coordinates[1][4][1], "P");
u8g2.drawStr(coordinates[1][5][0], coordinates[1][5][1], "P");
u8g2.drawStr(coordinates[1][6][0], coordinates[1][6][1], "P");
u8g2.drawStr(coordinates[1][7][0], coordinates[1][7][1], "P");
u8g2.drawStr(coordinates[7][4][0], coordinates[7][4][1], "O");
u8g2.drawStr(coordinates[7][5][0], coordinates[7][5][1], "I");
u8g2.drawStr(coordinates[7][1][0], coordinates[7][1][1], "I");
u8g2.drawStr(coordinates[7][0][0], coordinates[7][0][1], "S");
u8g2.drawStr(coordinates[7][7][0], coordinates[7][7][1], "S");
u8g2.drawStr(coordinates[7][2][0], coordinates[7][2][1], "C");
u8g2.drawStr(coordinates[7][6][0], coordinates[7][6][1], "C");
u8g2.drawStr(coordinates[7][3][0], coordinates[7][3][1], "F");
u8g2.drawStr(coordinates[6][0][0], coordinates[6][0][1], "U");
u8g2.drawStr(coordinates[6][1][0], coordinates[6][1][1], "U");
u8g2.drawStr(coordinates[6][2][0], coordinates[6][2][1], "U");
u8g2.drawStr(coordinates[6][3][0], coordinates[6][3][1], "U");
u8g2.drawStr(coordinates[6][4][0], coordinates[6][4][1], "U");
u8g2.drawStr(coordinates[6][5][0], coordinates[6][5][1], "U");
u8g2.drawStr(coordinates[6][6][0], coordinates[6][6][1], "U");
u8g2.drawStr(coordinates[6][7][0], coordinates[6][7][1], "U");
}
void calculateDiagonalMoves(int initial_x, int initial_y, int dx, int dy) {
int x = initial_x;
int y = initial_y;
Serial.print("Initial coordinates: (");
Serial.print(x);
Serial.print(", ");
Serial.print(y);
Serial.println(")");
while (x >= 0 && x <= 7 && y >= 0 && y <= 7) {
Serial.print("Current coordinates: (");
Serial.print(x);
Serial.print(", ");
Serial.print(y);
Serial.println(")");
x += dx;
y += dy;
}
Serial.print("Final coordinates: (");
Serial.print(x - dx); // Adjust to print the last valid coordinates
Serial.print(", ");
Serial.print(y - dy);
Serial.println(")");
if (x < 0 || x > 7 || y < 0 || y > 7) {
Serial.println("Out of bounds! Calculation stopped.");
}
}
void calculateBishopMoves(int initial_x, int initial_y) {
// Call calculateDiagonalMoves for each direction
calculateDiagonalMoves(initial_x, initial_y, 1, -1); // xadd_yminus
calculateDiagonalMoves(initial_x, initial_y, -1, -1); // xminus_yminus
calculateDiagonalMoves(initial_x, initial_y, 1, 1); // xadd_yadd
calculateDiagonalMoves(initial_x, initial_y, -1, 1); // xminus_yadd
}
void calculateKnightMoves(int initial_x1, int initial_y1) {
// Define all possible knight move combinations
int knightMoves[8][2] = {
{2, -1}, {2, 1}, // x2+ y- and x2+ y+
{-2, -1}, {-2, 1}, // x2- y- and x2- y+
{1, -2}, {1, 2}, // y2+ x- and y2+ x+
{-1, -2}, {-1, 2} // y2- x- and y2- x+
};
Serial.print("Initial coordinates: (");
Serial.print(initial_x1);
Serial.print(", ");
Serial.print(initial_y1);
Serial.println(")");
// Iterate through each possible move
for (int i = 0; i < 8; ++i) {
int dx = knightMoves[i][0];
int dy = knightMoves[i][1];
int x = initial_x1 + dx;
int y = initial_y1 + dy;
// Check if the new position is within the chessboard boundaries (0 to 7)
if (x >= 0 && x <= 7 && y >= 0 && y <= 7) {
Serial.print("Move ");
Serial.print(i + 1); // Display move number
Serial.print(": (");
Serial.print(dx > 0 ? "+" : ""); // Print + sign for positive dx
Serial.print(dx);
Serial.print(", ");
Serial.print(dy > 0 ? "+" : ""); // Print + sign for positive dy
Serial.print(dy);
Serial.print(") -> (");
Serial.print(x);
Serial.print(", ");
Serial.print(y);
Serial.println(")");
}
}
}
void calculateRookMoves(int initial_x2, int initial_y2) {
// Define all possible rook move directions (x+, x-, y+, y-)
int rookMoves[4][2] = {
{1, 0}, {-1, 0}, // x+ and x-
{0, 1}, {0, -1} // y+ and y-
};
Serial.print("Initial coordinates: (");
Serial.print(initial_x2);
Serial.print(", ");
Serial.print(initial_y2);
Serial.println(")");
// Iterate through each possible move direction
for (int i = 0; i < 4; ++i) {
int dx = rookMoves[i][0];
int dy = rookMoves[i][1];
int x2 = initial_x2 + dx;
int y2 = initial_y2 + dy;
// Continue moving in the same direction until out of bounds (0 to 7)
while (x2 >= 0 && x2 <= 7 && y2 >= 0 && y2 <= 7) {
Serial.print("Move ");
Serial.print(i + 1); // Display move number
Serial.print(": (");
Serial.print(dx > 0 ? "+" : ""); // Print + sign for positive dx
Serial.print(dx);
Serial.print(", ");
Serial.print(dy > 0 ? "+" : ""); // Print + sign for positive dy
Serial.print(dy);
Serial.print(") -> (");
Serial.print(x2);
Serial.print(", ");
Serial.print(y2);
Serial.println(")");
x2 += dx;
y2 += dy;
}
}
}
void calculateQueenMoves(int initial_x3, int initial_y3) {
// Calculate rook-like moves
calculateRookMoves(initial_x3, initial_y3);
// Calculate bishop-like moves
calculateBishopMoves(initial_x3, initial_y3);
}
void calculateKingMoves(int initial_x4, int initial_y4) {
// Define all possible king move combinations
int kingMoves[8][2] = {
{1, 0}, {-1, 0}, // x+ y0 and x- y0
{0, 1}, {0, -1}, // y+ x0 and y- x0
{1, 1}, {1, -1}, // x+ y+ and x+ y-
{-1, 1}, {-1, -1} // x- y+ and x- y-
};
Serial.print("Initial coordinates: (");
Serial.print(initial_x4);
Serial.print(", ");
Serial.print(initial_y4);
Serial.println(")");
// Iterate through each possible move
for (int i = 0; i < 8; ++i) {
int dx = kingMoves[i][0];
int dy = kingMoves[i][1];
int x = initial_x4 + dx;
int y = initial_y4 + dy;
// Check if the new position is within the chessboard boundaries (0 to 7)
if (x >= 0 && x <= 7 && y >= 0 && y <= 7) {
Serial.print("Move ");
Serial.print(i + 1); // Display move number
Serial.print(": (");
Serial.print(dx > 0 ? "+" : ""); // Print + sign for positive dx
Serial.print(dx);
Serial.print(", ");
Serial.print(dy > 0 ? "+" : ""); // Print + sign for positive dy
Serial.print(dy);
Serial.print(") -> (");
Serial.print(x);
Serial.print(", ");
Serial.print(y);
Serial.println(")");
}
}
}