summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.cache/clangd/index/main.c.B35546292B5EA1F4.idxbin1840 -> 3382 bytes
-rw-r--r--.cache/clangd/index/ring.h.D0AA315870801682.idxbin422 -> 576 bytes
-rw-r--r--.gitignore1
-rw-r--r--src/.deps/tower_of_hanoi_curses-holder.Po8
-rw-r--r--src/Makefile.am2
-rw-r--r--src/Makefile.in57
-rw-r--r--src/main.c43
-rw-r--r--src/ring.c26
-rw-r--r--src/ring.h10
-rw-r--r--src/tower.c (renamed from src/holder.c)2
-rw-r--r--src/tower.h (renamed from src/holder.h)13
11 files changed, 120 insertions, 42 deletions
diff --git a/.cache/clangd/index/main.c.B35546292B5EA1F4.idx b/.cache/clangd/index/main.c.B35546292B5EA1F4.idx
index eb0d92f..a5094ec 100644
--- a/.cache/clangd/index/main.c.B35546292B5EA1F4.idx
+++ b/.cache/clangd/index/main.c.B35546292B5EA1F4.idx
Binary files differ
diff --git a/.cache/clangd/index/ring.h.D0AA315870801682.idx b/.cache/clangd/index/ring.h.D0AA315870801682.idx
index 9ca4f29..acdc302 100644
--- a/.cache/clangd/index/ring.h.D0AA315870801682.idx
+++ b/.cache/clangd/index/ring.h.D0AA315870801682.idx
Binary files differ
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..16d3c4d
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+.cache
diff --git a/src/.deps/tower_of_hanoi_curses-holder.Po b/src/.deps/tower_of_hanoi_curses-holder.Po
new file mode 100644
index 0000000..ea25e32
--- /dev/null
+++ b/src/.deps/tower_of_hanoi_curses-holder.Po
@@ -0,0 +1,8 @@
+tower_of_hanoi_curses-holder.o: holder.c /usr/include/stdc-predef.h \
+ holder.h /usr/lib/gcc/x86_64-redhat-linux/8/include/stdbool.h
+
+/usr/include/stdc-predef.h:
+
+holder.h:
+
+/usr/lib/gcc/x86_64-redhat-linux/8/include/stdbool.h:
diff --git a/src/Makefile.am b/src/Makefile.am
index 453b5f5..3cf6686 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,4 +1,4 @@
bin_PROGRAMS = tower-of-hanoi-curses
-tower_of_hanoi_curses_SOURCES = main.c holder.c holder.h ring.h
+tower_of_hanoi_curses_SOURCES = main.c tower.c tower.h ring.c ring.h
tower_of_hanoi_curses_LDADD = @CURSES_LIBS@
tower_of_hanoi_curses_CPPFLAGS = @CURSES_CFLAGS@
diff --git a/src/Makefile.in b/src/Makefile.in
index 605dc50..ba0ac54 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -101,7 +101,8 @@ am__installdirs = "$(DESTDIR)$(bindir)"
PROGRAMS = $(bin_PROGRAMS)
am_tower_of_hanoi_curses_OBJECTS = \
tower_of_hanoi_curses-main.$(OBJEXT) \
- tower_of_hanoi_curses-holder.$(OBJEXT)
+ tower_of_hanoi_curses-tower.$(OBJEXT) \
+ tower_of_hanoi_curses-ring.$(OBJEXT)
tower_of_hanoi_curses_OBJECTS = $(am_tower_of_hanoi_curses_OBJECTS)
tower_of_hanoi_curses_DEPENDENCIES =
AM_V_P = $(am__v_P_@AM_V@)
@@ -119,8 +120,9 @@ am__v_at_1 =
DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)
depcomp = $(SHELL) $(top_srcdir)/depcomp
am__maybe_remake_depfiles = depfiles
-am__depfiles_remade = ./$(DEPDIR)/tower_of_hanoi_curses-holder.Po \
- ./$(DEPDIR)/tower_of_hanoi_curses-main.Po
+am__depfiles_remade = ./$(DEPDIR)/tower_of_hanoi_curses-main.Po \
+ ./$(DEPDIR)/tower_of_hanoi_curses-ring.Po \
+ ./$(DEPDIR)/tower_of_hanoi_curses-tower.Po
am__mv = mv -f
AM_V_lt = $(am__v_lt_@AM_V@)
am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
@@ -255,7 +257,7 @@ target_alias = @target_alias@
top_build_prefix = @top_build_prefix@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
-tower_of_hanoi_curses_SOURCES = main.c holder.c holder.h ring.h
+tower_of_hanoi_curses_SOURCES = main.c tower.c tower.h ring.c ring.h
tower_of_hanoi_curses_LDADD = @CURSES_LIBS@
tower_of_hanoi_curses_CPPFLAGS = @CURSES_CFLAGS@
all: all-am
@@ -344,8 +346,9 @@ mostlyclean-compile:
distclean-compile:
-rm -f *.tab.c
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tower_of_hanoi_curses-holder.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tower_of_hanoi_curses-main.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tower_of_hanoi_curses-ring.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tower_of_hanoi_curses-tower.Po@am__quote@ # am--include-marker
$(am__depfiles_remade):
@$(MKDIR_P) $(@D)
@@ -381,19 +384,33 @@ tower_of_hanoi_curses-main.obj: main.c
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(tower_of_hanoi_curses_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o tower_of_hanoi_curses-main.obj `if test -f 'main.c'; then $(CYGPATH_W) 'main.c'; else $(CYGPATH_W) '$(srcdir)/main.c'; fi`
-tower_of_hanoi_curses-holder.o: holder.c
-@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(tower_of_hanoi_curses_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT tower_of_hanoi_curses-holder.o -MD -MP -MF $(DEPDIR)/tower_of_hanoi_curses-holder.Tpo -c -o tower_of_hanoi_curses-holder.o `test -f 'holder.c' || echo '$(srcdir)/'`holder.c
-@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/tower_of_hanoi_curses-holder.Tpo $(DEPDIR)/tower_of_hanoi_curses-holder.Po
-@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='holder.c' object='tower_of_hanoi_curses-holder.o' libtool=no @AMDEPBACKSLASH@
+tower_of_hanoi_curses-tower.o: tower.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(tower_of_hanoi_curses_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT tower_of_hanoi_curses-tower.o -MD -MP -MF $(DEPDIR)/tower_of_hanoi_curses-tower.Tpo -c -o tower_of_hanoi_curses-tower.o `test -f 'tower.c' || echo '$(srcdir)/'`tower.c
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/tower_of_hanoi_curses-tower.Tpo $(DEPDIR)/tower_of_hanoi_curses-tower.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='tower.c' object='tower_of_hanoi_curses-tower.o' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(tower_of_hanoi_curses_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o tower_of_hanoi_curses-holder.o `test -f 'holder.c' || echo '$(srcdir)/'`holder.c
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(tower_of_hanoi_curses_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o tower_of_hanoi_curses-tower.o `test -f 'tower.c' || echo '$(srcdir)/'`tower.c
-tower_of_hanoi_curses-holder.obj: holder.c
-@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(tower_of_hanoi_curses_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT tower_of_hanoi_curses-holder.obj -MD -MP -MF $(DEPDIR)/tower_of_hanoi_curses-holder.Tpo -c -o tower_of_hanoi_curses-holder.obj `if test -f 'holder.c'; then $(CYGPATH_W) 'holder.c'; else $(CYGPATH_W) '$(srcdir)/holder.c'; fi`
-@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/tower_of_hanoi_curses-holder.Tpo $(DEPDIR)/tower_of_hanoi_curses-holder.Po
-@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='holder.c' object='tower_of_hanoi_curses-holder.obj' libtool=no @AMDEPBACKSLASH@
+tower_of_hanoi_curses-tower.obj: tower.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(tower_of_hanoi_curses_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT tower_of_hanoi_curses-tower.obj -MD -MP -MF $(DEPDIR)/tower_of_hanoi_curses-tower.Tpo -c -o tower_of_hanoi_curses-tower.obj `if test -f 'tower.c'; then $(CYGPATH_W) 'tower.c'; else $(CYGPATH_W) '$(srcdir)/tower.c'; fi`
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/tower_of_hanoi_curses-tower.Tpo $(DEPDIR)/tower_of_hanoi_curses-tower.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='tower.c' object='tower_of_hanoi_curses-tower.obj' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(tower_of_hanoi_curses_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o tower_of_hanoi_curses-holder.obj `if test -f 'holder.c'; then $(CYGPATH_W) 'holder.c'; else $(CYGPATH_W) '$(srcdir)/holder.c'; fi`
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(tower_of_hanoi_curses_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o tower_of_hanoi_curses-tower.obj `if test -f 'tower.c'; then $(CYGPATH_W) 'tower.c'; else $(CYGPATH_W) '$(srcdir)/tower.c'; fi`
+
+tower_of_hanoi_curses-ring.o: ring.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(tower_of_hanoi_curses_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT tower_of_hanoi_curses-ring.o -MD -MP -MF $(DEPDIR)/tower_of_hanoi_curses-ring.Tpo -c -o tower_of_hanoi_curses-ring.o `test -f 'ring.c' || echo '$(srcdir)/'`ring.c
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/tower_of_hanoi_curses-ring.Tpo $(DEPDIR)/tower_of_hanoi_curses-ring.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='ring.c' object='tower_of_hanoi_curses-ring.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(tower_of_hanoi_curses_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o tower_of_hanoi_curses-ring.o `test -f 'ring.c' || echo '$(srcdir)/'`ring.c
+
+tower_of_hanoi_curses-ring.obj: ring.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(tower_of_hanoi_curses_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT tower_of_hanoi_curses-ring.obj -MD -MP -MF $(DEPDIR)/tower_of_hanoi_curses-ring.Tpo -c -o tower_of_hanoi_curses-ring.obj `if test -f 'ring.c'; then $(CYGPATH_W) 'ring.c'; else $(CYGPATH_W) '$(srcdir)/ring.c'; fi`
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/tower_of_hanoi_curses-ring.Tpo $(DEPDIR)/tower_of_hanoi_curses-ring.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='ring.c' object='tower_of_hanoi_curses-ring.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(tower_of_hanoi_curses_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o tower_of_hanoi_curses-ring.obj `if test -f 'ring.c'; then $(CYGPATH_W) 'ring.c'; else $(CYGPATH_W) '$(srcdir)/ring.c'; fi`
ID: $(am__tagged_files)
$(am__define_uniq_tagged_files); mkid -fID $$unique
@@ -522,8 +539,9 @@ clean: clean-am
clean-am: clean-binPROGRAMS clean-generic mostlyclean-am
distclean: distclean-am
- -rm -f ./$(DEPDIR)/tower_of_hanoi_curses-holder.Po
- -rm -f ./$(DEPDIR)/tower_of_hanoi_curses-main.Po
+ -rm -f ./$(DEPDIR)/tower_of_hanoi_curses-main.Po
+ -rm -f ./$(DEPDIR)/tower_of_hanoi_curses-ring.Po
+ -rm -f ./$(DEPDIR)/tower_of_hanoi_curses-tower.Po
-rm -f Makefile
distclean-am: clean-am distclean-compile distclean-generic \
distclean-tags
@@ -569,8 +587,9 @@ install-ps-am:
installcheck-am:
maintainer-clean: maintainer-clean-am
- -rm -f ./$(DEPDIR)/tower_of_hanoi_curses-holder.Po
- -rm -f ./$(DEPDIR)/tower_of_hanoi_curses-main.Po
+ -rm -f ./$(DEPDIR)/tower_of_hanoi_curses-main.Po
+ -rm -f ./$(DEPDIR)/tower_of_hanoi_curses-ring.Po
+ -rm -f ./$(DEPDIR)/tower_of_hanoi_curses-tower.Po
-rm -f Makefile
maintainer-clean-am: distclean-am maintainer-clean-generic
diff --git a/src/main.c b/src/main.c
index 7218f3a..54d375f 100644
--- a/src/main.c
+++ b/src/main.c
@@ -2,19 +2,20 @@
#include <string.h>
#include "config.h"
-#include "holder.h"
+#include "tower.h"
#include "ring.h"
void draw_title();
void draw_body();
-void draw_holder(int ring_index, int startx, int starty);
+void draw_tower(int ring_index, int startx, int starty);
void input_loop();
WINDOW *wmain;
WINDOW *wbody;
Ring rings[3];
-Holder holders[3];
-int hover = 0; // initially, hover over the leftmost holder
+Ring *held = NULL;
+Tower towers[3];
+int hover = 0; // initially, hover over the leftmost tower
int main()
{
@@ -27,12 +28,13 @@ int main()
for(i = 2; i >= 0; --i) {
rings[i].size = i;
rings[i].location = 0;
+ rings[i].held = false;
}
- // initialize holders
- memset(holders[0].rings, true, 3);
- memset(holders[1].rings, false, 3);
- memset(holders[2].rings, false, 3);
+ // initialize towers
+ memset(towers[0].rings, true, 3);
+ memset(towers[1].rings, false, 3);
+ memset(towers[2].rings, false, 3);
wmain = initscr();
cbreak();
@@ -42,7 +44,7 @@ int main()
// draw layout
draw_title();
- wbody = newwin(7, getmaxx(wmain), 10, 0);
+ wbody = newwin(9, getmaxx(wmain), 8, 0);
draw_body();
refresh();
@@ -62,9 +64,9 @@ void draw_title() {
void draw_body() {
werase(wbody);
- draw_holder(0, getmaxx(wbody)/4 - 4, 6);
- draw_holder(1, getmaxx(wbody)/2 - 4, 6);
- draw_holder(2, 3*getmaxx(wbody)/4 - 4, 6);
+ draw_tower(0, getmaxx(wbody)/4 - 4, 8);
+ draw_tower(1, getmaxx(wbody)/2 - 4, 8);
+ draw_tower(2, 3*getmaxx(wbody)/4 - 4, 8);
// FIXME placeholder implementation
/*
@@ -84,7 +86,7 @@ void draw_body() {
*/
}
-void draw_holder(int ring_index, int startx, int starty) {
+void draw_tower(int ring_index, int startx, int starty) {
int count;
int i;
@@ -94,7 +96,7 @@ void draw_holder(int ring_index, int startx, int starty) {
count = 4;
mvwprintw(wbody, starty, startx, "---------");
for(i = 0; i < 3; ++i) {
- if(holders[ring_index].rings[i]) {
+ if(towers[ring_index].rings[i] && !rings[i].held) {
mvwprintw(wbody, getcury(wbody)-1, startx, rings[i].ascii);
--count;
}
@@ -105,6 +107,11 @@ void draw_holder(int ring_index, int startx, int starty) {
}
mvwprintw(wbody, getcury(wbody)-1, startx, " ^ ");
+ // draw held ring above the others
+ if(held != NULL && held->location == ring_index) {
+ mvwprintw(wbody, getcury(wbody)-2, startx, held->ascii);
+ }
+
wattroff(wbody, A_BOLD);
}
@@ -127,6 +134,14 @@ void input_loop() {
wrefresh(wbody);
break;
+ // pickup a ring
+ case ' ': // spacebar
+ // TODO check if a ring is already held, in which case we need to do something else
+ pickup_ring();
+ draw_body();
+ wrefresh(wbody);
+ break;
+
}
}
}
diff --git a/src/ring.c b/src/ring.c
new file mode 100644
index 0000000..633648b
--- /dev/null
+++ b/src/ring.c
@@ -0,0 +1,26 @@
+#include <assert.h>
+#include <stdlib.h>
+
+#include "ring.h"
+#include "tower.h"
+
+void pickup_ring() {
+ int i;
+ int pickup = -1;
+
+ // should not be called if we are already holding a ring
+ assert(held == NULL);
+
+ // find the smallest ring on the currently hovered tower (if there is one)
+ for(i = 2; i >= 0; --i) {
+ if(rings[i].location == hover) {
+ pickup = i;
+ break;
+ }
+ }
+
+ if(pickup > 0) {
+ held = &rings[pickup];
+ held->held = true;
+ }
+}
diff --git a/src/ring.h b/src/ring.h
index 0836421..0b23bf1 100644
--- a/src/ring.h
+++ b/src/ring.h
@@ -1,10 +1,18 @@
#ifndef RING_H
#define RING_H
+#include <stdbool.h>
+
typedef struct ring {
int size;
int location;
- char ascii[9];
+ char ascii[10];
+ bool held;
} Ring;
+extern Ring rings[3];
+extern Ring *held;
+
+void pickup_ring();
+
#endif
diff --git a/src/holder.c b/src/tower.c
index d15f2cb..9220db2 100644
--- a/src/holder.c
+++ b/src/tower.c
@@ -1,4 +1,4 @@
-#include "holder.h"
+#include "tower.h"
int hover_max = 2;
diff --git a/src/holder.h b/src/tower.h
index e1306d3..6fed8cd 100644
--- a/src/holder.h
+++ b/src/tower.h
@@ -1,15 +1,16 @@
-#ifndef HOLDER_H
-#define HOLDER_H
+#ifndef TOWER_H
+#define TOWER_H
#include <stdbool.h>
+typedef struct tower {
+ bool rings[3];
+} Tower;
+
+extern Tower towers[3];
extern int hover;
void hover_move_right();
void hover_move_left();
-typedef struct holder {
- bool rings[3];
-} Holder;
-
#endif