moved some stuff around

This commit is contained in:
Karma Riuk 2025-02-02 15:15:14 +01:00
parent 139a5c7d8f
commit 85a5bfa328
11 changed files with 76 additions and 35 deletions

32
cpp/Makefile Normal file
View File

@ -0,0 +1,32 @@
# Compiler flags (add -O2 for optimization, -g for debugging, etc.)
CXXFLAGS = -Wall -O3
# Name of the final executable
TARGET = stickfosh
# List of source files
SRCS = main.cpp board.cpp
# Automatically generate object file names from source file names
OBJS = $(SRCS:.cpp=.o)
# Default rule: build the target executable
all: $(TARGET)
# Link the object files into the final executable
$(TARGET): $(OBJS)
$(CXX) $(CXXFLAGS) -o $(TARGET) $(OBJS)
# Pattern rule: compile each .cpp file to a .o file
%.o: %.cpp %.hpp
$(CXX) $(CXXFLAGS) -c $< -o $@
main.o: board.o
stickfosh: main.o board.o
# Clean rule to remove built files
clean:
rm -f $(TARGET) $(OBJS)
# Optional: a rule to rebuild everything from scratch
rebuild: clean all

View File

@ -1,38 +1,7 @@
#include "board.hpp"
#include <cctype>
#include <map>
#include <string>
enum Piece {
None = 0,
King = 1,
Pawn = 2,
Knigt = 3,
Bishop = 4,
Rook = 5,
Queen = 6,
};
enum Colour {
White = 8,
Black = 16,
};
enum CastleRights {
KingSide = 1,
QueenSide = 2,
};
class Board {
private:
int squares[64] = {Piece::None};
Colour turn;
int castle_rights;
public:
static Board* setup_fen_position(std::string fen);
std::string to_fen();
};
Board* Board::setup_fen_position(std::string fen) {
Board* board = new Board();

22
cpp/board.hpp Normal file
View File

@ -0,0 +1,22 @@
#pragma once
#include "piece.hpp"
#include <string>
enum CastleRights {
KingSide = 1,
QueenSide = 2,
};
class Board {
private:
int8_t squares[64] = {Piece::None};
Colour turn;
int8_t castle_rights;
public:
static Board* setup_fen_position(std::string fen);
std::string to_fen();
};

BIN
cpp/board.o Normal file

Binary file not shown.

BIN
cpp/main Executable file

Binary file not shown.

View File

@ -1,4 +1,4 @@
#include "board.cpp"
#include "board.hpp"
#include <iostream>
@ -7,6 +7,10 @@ int main(int argc, char* argv[]) {
"rnbq1k1r/pp1Pbppp/2p5/8/2B5/8/PPP1NnPP/RNBQK2R w KQ - 1 8";
Board* b = Board::setup_fen_position(pos);
std::cout << sizeof(Board) << std::endl;
std::cout << sizeof(int8_t[64]) << std::endl;
std::cout << sizeof(Colour) << std::endl;
std::string fen = b->to_fen();
std::cout << pos << std::endl;

BIN
cpp/main.o Normal file

Binary file not shown.

14
cpp/piece.hpp Normal file
View File

@ -0,0 +1,14 @@
enum Piece {
None = 0,
King = 1,
Pawn = 2,
Knigt = 3,
Bishop = 4,
Rook = 5,
Queen = 6,
};
enum Colour {
White = 8,
Black = 16,
};

BIN
cpp/stickfosh Executable file

Binary file not shown.

View File

@ -1,5 +1,5 @@
#include "../board.cpp"
#include "lib.cpp"
#include "lib.hpp"
int main() {
std::string pos = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR";