Skip to content

Commit

Permalink
fix some rough corners
Browse files Browse the repository at this point in the history
  • Loading branch information
kspalaiologos committed Nov 11, 2023
1 parent 019ab1b commit dcf640c
Show file tree
Hide file tree
Showing 15 changed files with 114 additions and 599 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ sdlmine/config.h.in~
imgui/.deps/

imgui/.dirstamp

spidersol/configure~
14 changes: 7 additions & 7 deletions sdlmine/minesweeper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ int may_restart = 0, game_over = 0, game_start, counter2 = 0;

int timer_started = 0, mouth_idx = 0;

ImGuiIO io;
ImGuiIO * io;

#ifdef EMSCRIPTEN
#include <emscripten.h>
Expand Down Expand Up @@ -94,7 +94,7 @@ void game_loop(void) {
running = false;
break;
case SDL_MOUSEBUTTONDOWN:
if (io.WantCaptureMouse) break;
if (io->WantCaptureMouse) break;
if (event.button.button == SDL_BUTTON_LEFT) {
// If within the bounds of the face
SDL_Rect rect;
Expand All @@ -115,7 +115,7 @@ void game_loop(void) {
}
break;
case SDL_MOUSEBUTTONUP:
if (io.WantCaptureMouse) break;
if (io->WantCaptureMouse) break;
if (event.button.button == SDL_BUTTON_LEFT) {
// If within the bounds of the face
SDL_Rect rect;
Expand Down Expand Up @@ -397,10 +397,10 @@ int main(void) {

IMGUI_CHECKVERSION();
ImGui::CreateContext();
io = ImGui::GetIO();
(void)io;
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
io.IniFilename = NULL;
io = &ImGui::GetIO();
io->ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
io->IniFilename = NULL;
io->LogFilename = NULL;

ImGui::StyleColorsClassic();

Expand Down
12 changes: 6 additions & 6 deletions sdlreversi/reversi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ Uint32 animate(Uint32 interval, void * param) {

SDL_Window * window;
SDL_Renderer * renderer;
ImGuiIO io;
ImGuiIO * io;
char difficulty;
bool done = false;

Expand All @@ -277,7 +277,7 @@ void game_loop() {
while (SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_MOUSEBUTTONUP:
if (io.WantCaptureMouse) break;
if (io->WantCaptureMouse) break;
if (event.button.button == SDL_BUTTON_LEFT) {
int mx = event.button.x;
int my = event.button.y;
Expand Down Expand Up @@ -500,10 +500,10 @@ int main() {

IMGUI_CHECKVERSION();
ImGui::CreateContext();
io = ImGui::GetIO();
(void)io;
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
io.IniFilename = NULL;
io = &ImGui::GetIO();
io->ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
io->IniFilename = NULL;
io->LogFilename = NULL;

ImGui::StyleColorsClassic();

Expand Down
2 changes: 1 addition & 1 deletion spidersol/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ AM_CXXFLAGS = $(SDL_CFLAGS) $(SDL_ttf_CFLAGS)
AM_CFLAGS = $(SDL_CFLAGS) $(SDL_ttf_CFLAGS)
bin_PROGRAMS = spidersol

spidersol_SOURCES = cntrl.c engine.c infobox.c settings.c ui.c win.c deal.c game_state.c leaderboard.c spidersol.c undo.c
spidersol_SOURCES = cntrl.c engine.c infobox.c ui.c win.c deal.c game_state.c spidersol.cpp undo.c ../imgui/imgui.cpp ../imgui/imgui_impl_sdl2.cpp ../imgui/imgui_tables.cpp ../imgui/imgui_draw.cpp ../imgui/imgui_impl_sdlrenderer2.cpp ../imgui/imgui_widgets.cpp
spidersol_LDADD = $(SDL_LIBS) $(SDL_ttf_LIBS)
4 changes: 2 additions & 2 deletions spidersol/configure.ac
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
AC_PREREQ([2.71])
AC_INIT([spidersol], [1.0], [[email protected]])
AC_CONFIG_SRCDIR([spidersol.c])
AC_CONFIG_SRCDIR([spidersol.cpp])
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_AUX_DIR([build-aux])
AC_CONFIG_MACRO_DIR([build-aux])
AC_COPYRIGHT([Copyright (C) 2023 Kamila Szewczyk; licensed under the terms of the GNU GPLv3 license.])

AM_INIT_AUTOMAKE([foreign])
AM_INIT_AUTOMAKE([foreign subdir-objects])

# Checks for programs.
AC_PROG_CXX
Expand Down
85 changes: 2 additions & 83 deletions spidersol/engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,87 +34,6 @@ int has_moves() {

if (game.remainingExtraDeals > 0) return 1;

for (int i = 0; i < 10; i++) {
if (game.stacks[i].num_cards == 0) return 1;
}

// Compute the offsets in each stack that give a consecutive column slice.
int offsets[10];
compute_offsets(offsets);

// Check if there are any moves possible that won't just end up in a loop.
// E.g., if we move a 2 to a 3, but the 2 was previously on a 3, this makes no sense unless an entire stack is
// getting folded.

// In other words: Move only full stacks as defined from offsets[i] to stacks[i].num_cards, UNLESS the last card is
// an Ace and this operation will result in a full stack from king, queen, jack, etc... until an ace.

// Start with the easy case first: Check if any _full_ stack can be moved anywhere.

for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
if (i == j || offsets[i] == -1) continue;

// Can be moved!
if (game.stacks[i].cards[offsets[i]].value + 1 ==
game.stacks[j].cards[game.stacks[j].num_cards - 1].value &&
game.stacks[i].cards[offsets[i]].suit == game.stacks[j].cards[game.stacks[j].num_cards - 1].suit)
return 1;
}
}

// The difficult case:
// Mask out the stacks that start with a king and the stacks that end with an ace.

int ends[10], begins[10];
int ec[10], bc[10];

for (int i = 0; i < 10; i++) {
ends[i] = -1;
begins[i] = -1;
ec[i] = -1;
bc[i] = -1;
}

for (int i = 0; i < 10; i++) {
if (game.stacks[i].num_cards == 0 || offsets[i] == -1) continue;

if (game.stacks[i].cards[offsets[i]].value == 0) {
ends[i] = game.stacks[i].cards[game.stacks[i].num_cards - 1].value;
ec[i] = game.stacks[i].cards[game.stacks[i].num_cards - 1].suit;
}

if (game.stacks[i].cards[game.stacks[i].num_cards - 1].value == 12) {
begins[i] = game.stacks[i].cards[offsets[i]].value;
bc[i] = game.stacks[i].cards[offsets[i]].suit;
}
}

// Determine if there is such ends[i] and begins[j] that ends[i] <= begins[j]
// and i != j. If so, return 1.

for (int i = 0; i < 10; i++) {
if (ends[i] == -1) continue;

for (int j = 0; j < 10; j++) {
// stack begins with begins[j] and ends with Ace.
// stack starts with King and ends with ends[i].
// meaning that we're seeking for overlap in these two stacks.

// assume we have a run from K to 6 and from 8 to A.
// begins = 8, ends = 6, but it's reverse so ends > begins.

if (begins[j] == -1) continue;

if (i == j) continue;

if (ec[i] == bc[j] && begins[j] <= ends[i]) {
return 1;
}
}
}

// Assume no legal moves.

return 0;
// TODO.
return 1;
}
25 changes: 5 additions & 20 deletions spidersol/game_state.c
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@

#include "game_state.h"

#include "leaderboard.h"
#include "undo.h"

#include <stdio.h>

static char * fs_name() { return "solitaire.dat"; }

static void fs_flush_data(FILE * f) { fflush(f); }

#include <stdio.h>

struct game_data game = { .remainingExtraDeals = 5,
.timeDelta = -1,
.selected_card_back = 9,
Expand Down Expand Up @@ -38,8 +37,8 @@ void reset_game() {
}

void new_game() {
game.lastseed = time(NULL);
reset_game();
srand(game.lastseed = time(NULL));
}

void load_storage() {
Expand All @@ -51,14 +50,6 @@ void load_storage() {
return;
}

// Leaderboard entries.
for (int i = 0; i < 10; i++) {
fscanf(f, "%d %d %d %d\n", &game.leaderboard[i].score, &game.leaderboard[i].moves, &game.leaderboard[i].time,
&game.leaderboard[i].when);
}

onLeaderboardUpdate();

fscanf(f, "%d %d \n", &game.selected_card_back, &game.difficulty);
for (int i = 0; i < 8; i++) {
fscanf(f, "%d ", &game.wonKings[i]);
Expand Down Expand Up @@ -99,20 +90,14 @@ void save_storage() {
return;
}

// Leaderboard entries:
for (int i = 0; i < 10; i++) {
fprintf(f, "%d %d %d %d\n", game.leaderboard[i].score, game.leaderboard[i].moves, game.leaderboard[i].time,
game.leaderboard[i].when);
}

fprintf(f, "%d %d \n", game.selected_card_back, game.difficulty);
for (int i = 0; i < 8; i++) {
fprintf(f, "%d ", game.wonKings[i]);
}
fprintf(f, "\n");

// Synchronise the game state only if we're in the IDLE, LEADERBOARD or SETTINGS state.
if (game.state == STATE_GAME_IDLE || game.state == STATE_GAME_SETTINGS || game.state == STATE_GAME_LEADERBOARD) {
// Synchronise the game state only if we're in the IDLE state.
if (game.state == STATE_GAME_IDLE) {
fprintf(f, "1\n");
fprintf(f, "%d %d %d %d %d \n", game.points, game.time, game.moves, game.prevdiff, game.remainingExtraDeals);
for (int i = 0; i < 5; i++) {
Expand Down
11 changes: 0 additions & 11 deletions spidersol/game_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ enum {
STATE_GAME_DEAL,
STATE_GAME_DRAGGING_STACK,
STATE_GAME_DEALING_ROW,
STATE_GAME_SETTINGS,
STATE_GAME_FIREWORKS,
STATE_GAME_LEADERBOARD,
STATE_GAME_LOST
};

Expand All @@ -40,13 +38,6 @@ struct historical_state {
int remainingExtraDeals;
};

struct leaderboard_entry {
int score;
int moves;
int time;
time_t when;
};

struct game_data {
int remainingExtraDeals;
struct card extracards[5][10];
Expand All @@ -68,8 +59,6 @@ struct game_data {
int needsTextRepaint;

int counts[4][13];

struct leaderboard_entry leaderboard[10];
};

extern struct game_data game;
Expand Down
Loading

0 comments on commit dcf640c

Please sign in to comment.