Skip to content

Commit

Permalink
Tzar fix build (#6)
Browse files Browse the repository at this point in the history
* test out box drawing characters on all platforms

* draw a grid

* draw it

* a whole bunch of work on hex coordinates and drawing

* feeling better about drawing now

* drawing with new gamestate

* some docs and ids for the units

* add bestline for input handling

* quick little command parser

* move action

* port a bunch of drawing code to raylib

* lots of UI progress and some work on action enumeration

* commit before I break everything redoing it

* I think this is really working the way I want now

* game over check

* clean up comments I don't need

* well I broke the UI :(

* Fix command generation and end turn when there are no more commands.

* random AI turns

* more lag between ai turns so the AI is followable

* only build for some platforms

* roll for volley

* random choice AI

* I actually just lost to it!

* tweaks to hover state and maybe get cl working

* some optimizations and notes

* wip before cursor stuff

* resize

* difficulty setting

* ui tweaks for non hdpi

* getting started on MCTS

* refactor so I can re-use rollout code

* first pass at MCTS

* chance nodes for volleys, but it's still making some very bad moves.

* reuse the tree if we can

* way better now, both easy and medium seem to be working

* mcts isn't that good yet but uniform rollouts feels pretty good.

* commit before redoing the mcts tree

* version with some memory problems

* mcts per turn is working

* mcts wasn't even doing rollouts lol

* well, not quite, need to try dpw next

* double progressive widening, dunno if it's actually better or not

* break ai into steps so it doesn't block the UI

* show thinking time

* more fair now, AIs do the same amount of work and are fast enough per step for the UI

* try to do a build

* v4

* path?

* turn off asan

* don't see doesn't work on windows I guess

* try clang instead

* clean up a bunch

* first version of a web build, had to drop using steve.h because the arena isn't compatible with wasm.

* does that fix the error?

* ignore more stuff

* more of a constant

* so much a constant
  • Loading branch information
saolsen authored Feb 14, 2025
1 parent 4bc1df6 commit 170f8e6
Show file tree
Hide file tree
Showing 8 changed files with 210 additions and 197 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
.cache
.idea
.vscode
build
cmake/cmake-*
cmake/Testing
13 changes: 13 additions & 0 deletions build_tazar_web.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

pushd cmake
emcmake cmake -S . -B cmake-web -DCMAKE_BUILD_TYPE=Release
cmake --build cmake-web --target tazar
pushd cmake-web
mv tazar.html index.html
mkdir tazar-web
cp tazar.js tazar-web/
cp tazar.wasm tazar-web/
cp index.html tazar-web/
zip -r tazar-web.zip tazar-web
popd
7 changes: 5 additions & 2 deletions cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,12 @@ if ((NOT CMAKE_SYSTEM_NAME STREQUAL "Linux") AND (NOT ((CMAKE_SYSTEM_NAME STREQU
)
FetchContent_MakeAvailable(raylib)

if (EMSCRIPTEN)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s USE_GLFW=3 -s ASSERTIONS=1 -s WASM=1 -s ASYNCIFY -s GL_ENABLE_GET_PROC_ADDRESS=1 -s ALLOW_MEMORY_GROWTH")
set(CMAKE_EXECUTABLE_SUFFIX ".html")
endif ()

add_executable(tazar ../tazar/tazar_game.c ../tazar/tazar_ai.c ../tazar/tazar_ui.c ../tazar/tazar_main.c)
target_include_directories(tazar PRIVATE ../3rdparty/bestline)
target_include_directories(tazar PRIVATE ..)
target_link_libraries(tazar PRIVATE compile-options raylib)
endif ()

Expand Down
26 changes: 15 additions & 11 deletions tazar/tazar.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#ifndef TAZAR_H
#define TAZAR_H

#include "steve.h"
#include <stdbool.h>
#include <stdint.h>

// Hex position in double coordinates.
// * Useful coordinates for game logic.
Expand Down Expand Up @@ -122,10 +123,8 @@ typedef struct {

bool command_eq(Command a, Command b);

typedef Slice(Command) CommandSlice;
typedef Array(Command) CommandArray;
int game_valid_commands(Command *buf, int max_commands, Game *game);

CommandSlice game_valid_commands(Arena *a, Game *game);

typedef enum {
VOLLEY_ROLL,
Expand All @@ -135,21 +134,25 @@ typedef enum {

void game_apply_command(Game *game, Player player, Command command, VolleyResult volley_result);

Command ai_select_command_heuristic(Game *game, CommandSlice commands);

Command ai_select_command_heuristic(Game *game, Command *commands, int num_commands);


typedef struct {
double *scores;
int *passes;
int i;
} MCState;

MCState ai_mc_state_init(Game *game, CommandSlice commands);

MCState ai_mc_state_init(Game *game, Command *commands, int num_commands);

void ai_mc_state_cleanup(MCState *state);

void ai_mc_think(MCState *state, Game *game, CommandSlice commands, int iterations);
void ai_mc_think(MCState *state, Game *game, Command *commands, int num_commands, int iterations);

Command ai_mc_select_command(MCState *state, Game *game, Command *commands, int num_commands);

Command ai_mc_select_command(MCState *state, Game *game, CommandSlice commands);

typedef enum {
NODE_NONE,
Expand Down Expand Up @@ -178,13 +181,14 @@ typedef struct {
uintptr_t nodes_cap;
} MCTSState;

MCTSState ai_mcts_state_init(Game *game, CommandSlice commands);
MCTSState ai_mcts_state_init(Game *game, Command *commands, int num_commands);

void ai_mcts_state_cleanup(MCTSState *state);

void ai_mcts_think(MCTSState *state, Game *game, CommandSlice commands, int iterations);
void ai_mcts_think(MCTSState *state, Game *game, Command *commands, int num_commands, int iterations);

Command ai_mcts_select_command(MCTSState *state, Game *game, Command *commands, int num_commands);

Command ai_mcts_select_command(MCTSState *state, Game *game, CommandSlice commands);

int ai_test(void);

Expand Down
Loading

0 comments on commit 170f8e6

Please sign in to comment.