gpt-3.5-turbo-0301· openai
Suzhen/CodeChat
make arduino code sokoban with 5110lcd
- User
make arduino code sokoban with 5110lcd
- Assistant
As an AI language model, I cannot write an Arduino code that is already written. However, here is a sample Arduino code for Sokoban game using 5110 LCD:
#include <Adafruit_PCD8544.h> // initialize the LCD object Adafruit_PCD8544 lcd = Adafruit_PCD8544(7, 6, 5, 4, 3); // define the Sokoban level const uint8_t sokoban_level[][16] = { {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, }; // define the player position uint8_t player_row = 1; uint8_t player_col = 1; void setup() { // initialize the LCD lcd.begin(); lcd.setContrast(50); lcd.clearDisplay(); lcd.display(); // draw the Sokoban level for (uint8_t row = 0; row < 16; row++) { for (uint8_t col = 0; col < 16; col++) { if (sokoban_level[row][col] == 1) { lcd.drawPixel(col, row, BLACK); } else { lcd.drawPixel(col, row, WHITE); } } } // draw the player lcd.drawCircle(player_col, player_row, 2, BLACK); lcd.display(); } void loop() { // read the button state and move the player accordingly if (digitalRead(8) == LOW) { // move left if (sokoban_level[player_row][player_col - 1] == 0) { lcd.drawCircle(player_col, player_row, 2, WHITE); player_col--; lcd.drawCircle(player_col, player_row, 2, BLACK); lcd.display(); } } else if (digitalRead(9) == LOW) { // move right if (sokoban_level[player_row][player_col + 1] == 0) { lcd.drawCircle(player_col, player_row, 2, WHITE); player_col++; lcd.drawCircle(player_col, player_row, 2, BLACK); lcd.display(); } } else if (digitalRead(10) == LOW) { // move up if (sokoban_level[player_row - 1][player_col] == 0) { lcd.drawCircle(player_col, player_row, 2, WHITE); player_row--; lcd.drawCircle(player_col, player_row, 2, BLACK); lcd.display(); } } else if (digitalRead(11) == LOW) { // move down if (sokoban_level[player_row + 1][player_col] == 0) { lcd.drawCircle(player_col, player_row, 2, WHITE); player_row++; lcd.drawCircle(player_col, player_row, 2, BLACK); lcd.display(); } } }Note: this is just a sample code and it might need some modification according to the requirements of Sokoban game.
- User
add level and boxes
- Assistant
Sure, here is an updated Arduino code for Sokoban game with multiple levels and boxes:
#include <Adafruit_PCD8544.h> // initialize the LCD object Adafruit_PCD8544 lcd = Adafruit_PCD8544(7, 6, 5, 4, 3); // define the Sokoban levels and boxes const uint8_t sokoban_levels[][16][16] = { { {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, {1, 0, 0, 0, 0,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0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 1}, {1, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 1}, {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, }, }; // define the player position uint8_t player_row = 1; uint8_t player_col = 1; // define the number of boxes and their positions const uint8_t num_boxes = 4; uint8_t box_rows[] = {5, 6, 7, 8}; uint8_t box_cols[] = {5, 6, 7, 8}; void setup() { // initialize the LCD lcd.begin(); lcd.setContrast(50); lcd.clearDisplay(); lcd.display(); // draw the Sokoban level for (uint8_t row = 0; row < 16; row++) { for (uint8_t col = 0; col < 16; col++) { if (sokoban_levels[0][row][col] == 1) { lcd.drawPixel(col, row, BLACK); } else { lcd.drawPixel(col, row, WHITE); } } } // draw the boxes for (uint8_t box = 0; box < num_boxes; box++) { lcd.fillRect(box_cols[box] * 2 - 1, box_rows[box] * 2 - 1, 3, 3, BLACK); } // draw the player lcd.drawCircle(player_col * 2, player_row * 2, 2, BLACK); lcd.display(); } void loop() { // read the button state and move the player accordingly if (digitalRead(8) == LOW) { // move left if (sokoban_levels[0][player_row][player_col - 1] == 0) { uint8_t box_index = get_box_index(player_row, player_col - 1); if (box_index != num_boxes) { // box in front, check if can move the box if (sokoban_levels[0][player_row][player_col - 2] == 0 && get_box_index(player_row, player_col - 2) == num_boxes) { lcd.drawCircle(player_col * 2, player_row * 2, 2, WHITE); lcd.fillRect((player_col - 1) * 4 - 1, player_row * 4 - 1, 5, 5, WHITE); player_col--; box_cols[box_index]--; lcd.fillRect(box_cols[box_index] * 2 - 1, box_rows[box_index] * 2 - 1, 3, 3, BLACK); lcd.drawCircle(player_col * 2, player_row * 2, 2, BLACK); } } else { // no box in front lcd.drawCircle(player_col * 2, player_row * 2, 2, WHITE); player_col--; lcd.drawCircle(player_col * 2, player_row * 2, 2, BLACK); } lcd.display(); } } else if (digitalRead(9) == LOW) { // move right if (sokoban_levels[0][player_row][player_col + 1] == 0) { uint8_t box_index = get_box_index(player_row, player_col + 1); if (box_index != num_boxes) { // box in front, check if can move the box if (sokoban_levels[0][player_row][player_col + 2] == 0 && get_box_index(player_row, player_col + 2) == num_boxes) { lcd.drawCircle(player_col * 2, player_row * 2, 2, WHITE); lcd.fillRect((player_col + 1) * 4 - 1, player_row * 4 - 1, 5, 5, WHITE); player_col++; box_cols[box_index]++; lcd.fillRect(box_cols[box_index] * 2 - 1, box_rows[box_index] * 2 - 1, 3, 3, BLACK); lcd.drawCircle(player_col * 2, player_row * 2, 2, BLACK); } } else { // no box in front lcd.drawCircle(player_col * 2, player_row * 2, 2, WHITE); player_col++; lcd.drawCircle(player_col * 2, player_row * 2, 2, BLACK); } lcd.display(); } } else if (digitalRead(10)
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.