diff options
| author | tslil <tslil@posteo.de> | 2021-01-16 19:37:18 -0500 |
|---|---|---|
| committer | tslil <tslil@posteo.de> | 2026-08-28 19:37:41 +0100 |
| commit | 42a7a83a3bd81142038980c8e8cbbb40c41a5651 (patch) | |
| tree | 77c32222cd32e3a5a9c44c014a7833d9bb20d385 | |
| parent | 2ad167622077b875a3d4157d27690a575c9248af (diff) | |
It works, but it's too slowmcu
| -rw-r--r-- | .clang_complete | 2 | ||||
| -rw-r--r-- | Makefile | 6 | ||||
| -rw-r--r-- | src/ctaklm.c | 4 | ||||
| -rw-r--r-- | src/mcu.c | 70 |
4 files changed, 76 insertions, 6 deletions
diff --git a/.clang_complete b/.clang_complete index e9c2aee..c98e7b6 100644 --- a/.clang_complete +++ b/.clang_complete @@ -1,2 +1,4 @@ -Iinclude/ -I3rd-party/ +-I/usr/lib/gcc/avr/10.2.0/include/ +-I/usr/avr/include/ @@ -16,7 +16,7 @@ SIZE=size # ------------------------------------------------------------------- # MCU stuff -MCU=atmega32 +MCU=atmega32u4 F_CPU=20000000UL ACC=avr-gcc ACFLAGS=-Os -Wall -fpack-struct -fshort-enums -funsigned-bitfields -funsigned-char -I$(IDIR) @@ -24,7 +24,7 @@ AOBJCOPY=avr-objcopy AOBJSIZE=avr-size AVRDUDE=avrdude -ADFLAGS=-c usbasp -p t24 +ADFLAGS=-p $(MCU) -c avr109 -b 57600 -P /dev/serial/by-id/usb-Arduino_LLC_Arduino_Micro-if00 TARGET=mcu AHEX=$(TARGET).hex @@ -61,7 +61,7 @@ ASUMMARY: $(AOBJ) @$(AOBJSIZE) $(AOBJ) $(AHEX) upload: $(TARGET).hex - $(AVRDUDE) $(ADFLAGS) -U flash:w:$< + $(AVRDUDE) $(ADFLAGS) -D -U flash:w:$<:i clean: rm -f $(PROG) $(STAT) $(OBJS) diff --git a/src/ctaklm.c b/src/ctaklm.c index 68441c0..45b3043 100644 --- a/src/ctaklm.c +++ b/src/ctaklm.c @@ -198,8 +198,8 @@ handle_turn(char *line) { uint8_t new_win = (won == 0xFF); switch (do_ptn(line)) { // Errors - case PTN_INVALID: { puts("Invalid PTN."); return -1; break; } - case ACT_ILLEGAL: { puts("Illegal action."); return -1; break; } + case PTN_INVALID: { puts("Invalid PTN."); return EXIT_FAILURE; break; } + case ACT_ILLEGAL: { puts("Illegal action."); return EXIT_FAILURE; break; } case ACT_OVERFLOW: { puts("Move would cause internal overflow, select another."); return EXIT_FAILURE; @@ -2,7 +2,75 @@ #include <tak.h> #include <ct1986.h> +#define EXIT_SUCCESS 0 +#define EXIT_FAILURE -1 + +/* + * static int + * handle_turn(char *line) { + * // Track win state + * uint8_t new_win = (won == 0xFF); + * switch (do_ptn(line)) { + * // Errors + * case PTN_INVALID: { return EXIT_FAILURE; break; } + * case ACT_ILLEGAL: { return EXIT_FAILURE; break; } + * case ACT_OVERFLOW: { return EXIT_FAILURE; break; } + * // Game has ended + * case GAME_END: { + * // Did it end this turn? + * if (new_win) { + * switch (won) { + * case WIN_DRAW: { break; } + * case WIN_FLAT_BLACK: { break; } + * case WIN_FLAT_WHITE: { break; } + * case WIN_ROAD_BLACK: { break; } + * case WIN_ROAD_WHITE: { break; } + * } + * } + * if (! new_win) return EXIT_FAILURE; + * break; + * } + * // Valid, append to game log + * case PTN_VALID: + * case ACT_OK: { break; } + * } + * return EXIT_SUCCESS; + * } + */ + +static void +dot(const uint8_t depth) { + PORTD ^= _BV(4); +} + + +static int +ct1986_turn(const uint8_t max_depth) { + // Prepare progress bar + // Run the minimax + float minimax = ct1986_generate(max_depth); + // Failed to find a move? + if ((minimax <= -infty && (ply & 1) == 1) + ||(minimax >= infty && (ply & 1) == 0)) { + // puts("] Opponent concedes!"); + return EXIT_FAILURE; + } else { + do_ptn(ct1986_ptn); + return EXIT_SUCCESS; + } +} + + int main(void) { - while(1); + DDRD = _BV(0) | _BV(4); + PORTD = 0; + + reset_state(5); + ct1986_display_progress = ˙ + PORTD = _BV(0) | _BV(4); + ct1986_turn(1); + PORTD = 0; + + while (1); return 0; } |
