Skip to content

Commit 18ea005

Browse files
committed
feat: load initial code from files
1 parent 8f52ce3 commit 18ea005

File tree

6 files changed

+218
-209
lines changed

6 files changed

+218
-209
lines changed

app/public/base.cpp

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
2+
#include <iostream>
3+
#include <vector>
4+
#include <string>
5+
#include <sstream>
6+
#include <optional> // Include the optional header
7+
8+
// Define the Piece structure similar to Java's record
9+
struct Piece {
10+
char pieceType;
11+
char pieceColor;
12+
Piece(char type, char color) : pieceType(type), pieceColor(color) {}
13+
};
14+
15+
// Function to parse the board and return each cell's content as a vector of moves
16+
std::vector<std::vector<int>> findMove(const std::vector<std::vector<std::optional<Piece>>>& board, char playerColor) {
17+
// TODO: Implement logic to find the next move
18+
// The moves should be returned as a vector of 2-element vectors
19+
// The first element of the sequence should be the starting cell
20+
// Each subsequent 2-element vector should contain the x and y coordinates of the cell to move to
21+
return {};
22+
}
23+
24+
int main() {
25+
// Initialize a 10x10 board with std::optional<Piece>
26+
std::vector<std::vector<std::optional<Piece>>> board(10, std::vector<std::optional<Piece>>(10));
27+
char playerColor;
28+
29+
// Read the player's color
30+
std::cin >> playerColor;
31+
std::cin.ignore(); // Ignore the newline character after reading playerColor
32+
33+
// Read input line by line for the board
34+
for (int r = 0; r < 10; r++) {
35+
std::string line;
36+
std::getline(std::cin, line); // Read the entire line
37+
std::stringstream ss(line);
38+
std::string pieceCode;
39+
int c = 0;
40+
41+
// Split the line by commas
42+
while (std::getline(ss, pieceCode, ',')) {
43+
if (!pieceCode.empty()) {
44+
board[r][c] = Piece(pieceCode[0], pieceCode[1]); // Use std::optional to directly create a Piece
45+
} else {
46+
board[r][c].reset(); // Use reset() to clear the optional if it's empty
47+
}
48+
c++;
49+
}
50+
}
51+
52+
// Call the findMove function to find the next move
53+
std::vector<std::vector<int>> moves = findMove(board, playerColor);
54+
55+
if (moves.empty()) {
56+
// No moves found
57+
std::cerr << "No moves were returned." << std::endl;
58+
return 0;
59+
}
60+
61+
// Print the moves
62+
for (const auto& pos : moves) {
63+
std::cout << pos[0] << "," << pos[1] << std::endl;
64+
}
65+
66+
return 0;
67+
}

app/public/base.java

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
2+
import java.util.Scanner;
3+
4+
public class CheckersBoardParser {
5+
6+
private record Piece(char pieceType, char pieceColor) {}
7+
8+
public static void main(String[] args) {
9+
Scanner scanner = new Scanner(System.in);
10+
Piece[][] board = new Piece[10][10]; // Initialize a 10x10 board
11+
12+
char playerColor = scanner.nextLine().charAt(0);
13+
14+
// Read input line by line
15+
for (int r = 0; r < 10; r++) {
16+
String line = scanner.nextLine();
17+
String[] row = line.split(","); // Split the line by commas
18+
Piece[] pieceRow = new Piece[row.length];
19+
for (int c = 0; c < row.length; c++) {
20+
String pieceCode = row[c];
21+
if (!pieceCode.isEmpty()) {
22+
pieceRow[c] = new Piece(pieceCode.charAt(0), pieceCode.charAt(1));
23+
} else {
24+
pieceRow[c] = null; // Empty cells should be null
25+
}
26+
}
27+
28+
board[r] = pieceRow; // Add the row to the board
29+
}
30+
31+
// Close the scanner to avoid resource leak
32+
scanner.close();
33+
34+
// Call the findMove method to find the next move
35+
int[][] moves = findMove(board, playerColor);
36+
37+
if (moves == null) {
38+
// Error occured
39+
return;
40+
}
41+
42+
// Print the moves
43+
for (int[] pos : moves) {
44+
System.out.println(pos[0] + "," + pos[1]);
45+
}
46+
47+
}
48+
49+
// This method parses the board and returns each cell's content as an array of moves
50+
private static int[][] findMove(Piece[][] board, char playerColor) {
51+
// TODO: Implement logic to find the next move
52+
// The moves should be returned as an array of 2-element arrays
53+
// The first element of the sequence should be the starting cell
54+
// Each subsequent 2-element array should contain the x and y coordinates of the cell to move to
55+
return null;
56+
}
57+
}

app/public/base.py

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
2+
class Piece:
3+
def __init__(self, piece_type, piece_color):
4+
self.piece_type = piece_type
5+
self.piece_color = piece_color
6+
7+
def find_move(board, player_color):
8+
# TODO: Implement logic to find the next move
9+
# The moves should be returned as a list of 2-element lists
10+
# The first element of the sequence should be the starting cell
11+
# Each subsequent 2-element list should contain the x and y coordinates of the cell to move to
12+
return []
13+
14+
def main():
15+
board = [[None for _ in range(10)] for _ in range(10)] # Initialize a 10x10 board with None
16+
17+
# Read the player's color
18+
player_color = input().strip()[0]
19+
20+
# Read input line by line for the board
21+
for r in range(10):
22+
line = input().strip()
23+
row = line.split(',') # Split the line by commas
24+
25+
# Parse each element to a Piece object or None
26+
for c, piece_code in enumerate(row):
27+
if piece_code:
28+
board[r][c] = Piece(piece_code[0], piece_code[1])
29+
else:
30+
board[r][c] = None # Empty cells should be None
31+
32+
# Call the find_move function to find the next move
33+
moves = find_move(board, player_color)
34+
35+
if not moves:
36+
# No moves found
37+
raise Exception("No moves were returned.")
38+
return
39+
40+
# Print the moves
41+
for pos in moves:
42+
print(f"{pos[0]},{pos[1]}")
43+
44+
if __name__ == "__main__":
45+
main()

app/src/initCodeFiles.tsx

-187
This file was deleted.

0 commit comments

Comments
 (0)