Skip to content

Commit

Permalink
Finalize piet version
Browse files Browse the repository at this point in the history
  • Loading branch information
JanEricNitschke committed Oct 10, 2024
1 parent 313e31a commit b33c50a
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 63 deletions.
29 changes: 7 additions & 22 deletions .github/workflows/piet.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This workflow will run stuff on the piet version of tictactoe.

name: tpiet
name: piet

on:
push:
Expand All @@ -13,29 +13,14 @@ jobs:
runs-on: ubuntu-latest
defaults:
run:
working-directory: main/tictactoe_piet
working-directory: ./tictactoe_piet
steps:
- name: Checkout turnstyle
uses: actions/checkout@v4
with:
repository: JanEricNitschke/turnstyle
path: turnstyle
- name: Setup haskell
uses: haskell-actions/setup@v2
with:
ghc-version: '9.10.1'
- name: Checkout repo
uses: actions/checkout@v4
with:
path: main
- name: Install turnstyle
run: cabal install --user
working-directory: turnstyle
- name: Build
run: turnstyle compile -o CI.png tictactoe.txt
- name: Install dependencies
run: |
cargo install rpiet
- name: Run
run: |
turnstyle run tictactoe.png < input1.txt
turnstyle run tictactoe_opt.png < input1.txt
turnstyle run tictactoe.png < input2.txt
turnstyle run tictactoe_opt.png < input2.txt
rpiet tictactoe.png < input1.txt
rpiet tictactoe.png < input2.txt
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -481,9 +481,13 @@ tclsh tictactoe.tcl

Version using [Piet](https://www.dangermouse.net/esoteric/piet.html).

Developed using [MasterPiets](https://gabriellesc.github.io/piet/index.html) and [Pietron](https://github.com/dnek/pietron).

Logic of the individual components is defined in [PietLogic.txt](tictactoe_piet/PietLogic.txt).

Run with:
```
npiet tictactoe.png
rpiet tictactoe.png
```

## TicTacToe-scratch
Expand Down
3 changes: 3 additions & 0 deletions _typos.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
ba = "ba"
# Clojure settings.
edn = "edn"
# From piet version
Inpu = "Inpu"
fo = "fo"


[default]
Expand Down
1 change: 1 addition & 0 deletions tictactoe_piet/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
aux_mat/
109 changes: 69 additions & 40 deletions tictactoe_piet/PietLogic.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Default Stack: [P,0,1,2,3,4,5,6,7,8]

SetNth [N,P,0,1,2,3,4,5,6,7,8]: (N = 0 based indexing)
SetNth [N,P,0,1,2,3,4,5,6,7,8]: (N = 0 based indexing) DONE!
PUSH 2 -> [2,N,X,0,1,2,3,4,5,6,7,8]
ADD -> [N+2,X,0,1,2,3,4,5,6,7,8]
DUP -> [N+2,N+2,X,0,1,2,3,4,5,6,7,8]
Expand All @@ -20,7 +20,7 @@ PUSH 1 -> [1,N+2,X,X,0,1,2,4,5,6,7,8]
ROLL -> [X,0,1,2,X,4,5,6,7,8] (original Stack with board change)


GetNth [N,P,0,1,2,3,4,5,6,7,8]: (N = 0 based indexing)
GetNth [N,P,0,1,2,3,4,5,6,7,8]: (N = 0 based indexing) DONE!
PUSH 2 -> [2,N,P,0,1,2,3,4,5,6,7,8]
ADD -> [N+2,P,0,1,2,3,4,5,6,7,8]
DUP -> [N+2,N+2,P,0,1,2,3,4,5,6,7,8]
Expand All @@ -32,7 +32,7 @@ PUSH 1 -> [1,N+2,N+2,P,0,1,2,3,4,5,6,7,8,N+2]
SUB -> [N+1,N+2,P,0,1,2,3,4,5,6,7,8,N+2]
ROLL -> [3,P,0,1,2,4,5,6,7,8,N+2] (with example N=3)
DUP -> [3,3,P,0,1,2,4,5,6,7,8,N+2]
PUSH 13-> [13,3,3,P,0,1,2,4,5,6,7,8,N+2]
PUSH 12-> [13,3,3,P,0,1,2,4,5,6,7,8,N+2]
PUSH 1 -> [1,13,3,3,P,0,1,2,4,5,6,7,8,N+2]
ROLL -> [3,P,0,1,2,4,5,6,7,8,N+2,3]
PUSH 11-> [11,3,P,0,1,2,4,5,6,7,8,N+2,3]
Expand All @@ -44,7 +44,7 @@ PUSH 11-> [11,P,0,1,2,3,4,5,6,7,8,3]
PUSH 10-> [10,11,P,0,1,2,3,4,5,6,7,8,3]
ROLL -> [3,P,0,1,2,3,4,5,6,7,8] (Nth value + original Stack)

PrintBoard [P,0,1,2,3,4,5,6,7,8]:
PrintBoard [P,0,1,2,3,4,5,6,7,8]: DONE!
PUSH 10 -> [10,P,0,1,2,3,4,5,6,7,8]
PUSH 1 -> [1,10,P,0,1,2,3,4,5,6,7,8]
ROLL -> [0,1,2,3,4,5,6,7,8,P]
Expand Down Expand Up @@ -100,9 +100,9 @@ PUSH 10
PUSH 1
ROLL -> [P,0,1,2,3,4,5,6,7,8] (original stack)

EqualToPlayer [V,P,0,1,2,3,4,5,6,7,8]:
EqualToPlayer [V,P,0,1,2,3,4,5,6,7,8]: DONE!
PUSH 2 -> [2,V,P,0,1,2,3,4,5,6,7,8]
PUSH 1 -> [1,2V,P,0,1,2,3,4,5,6,7,8]
PUSH 1 -> [1,2,V,P,0,1,2,3,4,5,6,7,8]
ROLL -> [P,V,0,1,2,3,4,5,6,7,8]
DUP -> [P,P,V,0,1,2,3,4,5,6,7,8]
PUSH 3 -> [3,P,P,V,0,1,2,3,4,5,6,7,8]
Expand All @@ -111,43 +111,47 @@ ROLL -> [P,V,P,0,1,2,3,4,5,6,7,8]
SUB -> [V-P,P,0,1,2,3,4,5,6,7,8]
NOT -> [V==P,P,0,1,2,3,4,5,6,7,8]

ConditionCheck [X,Y,Z,P,0,1,2,3,4,5,6,7,8]:
ConditionCheck [X,Y,Z,P,0,1,2,3,4,5,6,7,8]: DONE!
PUSH 13 -> [13,X,Y,Z,P,0,1,2,3,4,5,6,7,8]
PUSH 2 -> [2,13,X,Y,Z,P,0,1,2,3,4,5,6,7,8]
ROLL -> [Z,P,0,1,2,3,4,5,6,7,8,X,Y]
EqualToPlayer -> [Z==P,P,0,1,2,3,4,5,6,7,8,X,Y]
PUSH 11 -> [11,Z==P,P,0,1,2,3,4,5,6,7,8,X,Y]
PUSH 1 -> [1,11,Z==P,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> [Y==P + Z==P + X==P - 3,P,0,1,2,3,4,5,6,7,8]
NOT -> [Y==P && Z==P && X==P,P,0,1,2,3,4,5,6,7,8]
GetNth -> [VY,P,0,1,2,3,4,5,6,7,8,Z==P,X]
EqualToPlayer -> [VY==P,P,0,1,2,3,4,5,6,7,8,VZ==P,X]
PUSH 11 -> [11,VY==P,P,0,1,2,3,4,5,6,7,8,VZ==P,X]
PUSH 1 -> [1,11,VY==P,P,0,1,2,3,4,5,6,7,8,VZ==P,X]
ROLL -> [P,0,1,2,3,4,5,6,7,8,VY==P,VZ==P,X]

PUSH 13 -> [13,P,0,1,2,3,4,5,6,7,8,VY==P,VZ==P,X]
PUSH 12 -> [12,13,P,0,1,2,3,4,5,6,7,8,VY==P,VZ==P,X]
ROLL -> [X,P,0,1,2,3,4,5,6,7,8,VY==P,VZ==P]
GetNth -> [VX,P,0,1,2,3,4,5,6,7,8,VY==P,VZ==P]
EqualToPlayer -> [VX==P,P,0,1,2,3,4,5,6,7,8,VY==P,VZ==P]

PUSH 13 -> [13,VX==P,P,0,1,2,3,4,5,6,7,8,VY==P,VZ==P]
PUSH 11 -> [11,13V,X==P,P,0,1,2,3,4,5,6,7,8,VY==P,VZ==P]
ROLL -> [VY==P,VZ==P,VX==P,P,0,1,2,3,4,5,6,7,8]
ADD -> [VY==P + VZ==P,VX==P,P,0,1,2,3,4,5,6,7,8]
ADD -> [VY==P + VZ==P + VX==P,P,0,1,2,3,4,5,6,7,8]
PUSH 3 -> [3,Y==P + Z==P + VX==P,P,0,1,2,3,4,5,6,7,8]
SUB -> [VY==P + VZ==P + VX==P - 3,P,0,1,2,3,4,5,6,7,8]
NOT -> [VY==P && VZ==P && VX==P,P,0,1,2,3,4,5,6,7,8]
-> [R,P,0,1,2,3,4,5,6,7,8] (R = 0 or 1)

CheckWinner [P,0,1,2,3,4,5,6,7,8]:

CheckWinner [P,0,1,2,3,4,5,6,7,8]: DONE!
PUSH 2 -> [2,P,0,1,2,3,4,5,6,7,8]
PUSH 1 -> [1,2,P,0,1,2,3,4,5,6,7,8]
PUSH 0 -> [0,1,2,P,0,1,2,3,4,5,6,7,8]
PUSH 1
PUSH 1
SUB -> [0,1,2,P,0,1,2,3,4,5,6,7,8]
ConditionCheck -> [R1,P,0,1,2,3,4,5,6,7,8]
PUSH 11
PUSH 1
Expand All @@ -171,7 +175,9 @@ ROLL -> [P,0,1,2,3,4,5,6,7,8,R3,R2,R1]

PUSH 6
PUSH 3
PUSH 0
PUSH 1
PUSH 1
SUB
ConditionCheck
PUSH 11
PUSH 1
Expand All @@ -196,7 +202,9 @@ ROLL -> [P,0,1,2,3,4,5,6,7,8,R3,R2,R1,C3,C2,C1]

PUSH 8
PUSH 4
PUSH 0
PUSH 1
PUSH 1
SUB
ConditionCheck
PUSH 11
PUSH 1
Expand All @@ -220,8 +228,10 @@ NOT -> [!(D1||R3||R2||R1||C3||C2||C1||D2),P,0,1,2,3,4,5,6,7,8]
NOT -> [D1||R3||R2||R1||C3||C2||C1||D2,P,0,1,2,3,4,5,6,7,8]
-> [R,P,0,1,2,3,4,5,6,7,8] (R = 0 or 1)

CheckFull [P,0,1,2,3,4,5,6,7,8]:
PUSH 0
CheckFull [P,0,1,2,3,4,5,6,7,8]: DONE!
PUSH 1
PUSH 1
SUB
GetNth -> [V0,P,0,1,2,3,4,5,6,7,8]
PUSH 45
SUB
Expand Down Expand Up @@ -314,7 +324,7 @@ ADD -> [V7==45+V6==45+V5==45+V4==45+V3==45+V2==45+V1==45+V0==45+V8==45,P,0,1
NOT -> [V7!=45&&V6!=45&&V5!=45&&V4!=45&&V3!=45&&V2!=45&&V1!=45&&V0!=45&&V8!=45,P,0,1,2,3,4,5,6,7,8]
-> [R,P,0,1,2,3,4,5,6,7,8] (R = 0 or 1)

PrintInput [P,0,1,2,3,4,5,6,7,8]:
PrintInput [P,0,1,2,3,4,5,6,7,8]: DONE!
PUSH 73
OUT_CHAR (I)
PUSH 110
Expand All @@ -331,7 +341,7 @@ PUSH 10
OUT_CHAR (Input:\n)
-> [P,0,1,2,3,4,5,6,7,8] (original board)

PrintDraw [P,0,1,2,3,4,5,6,7,8]:
PrintDraw [P,0,1,2,3,4,5,6,7,8]: DONE!
PUSH 68
OUT_CHAR (D)
PUSH 114
Expand All @@ -344,7 +354,7 @@ PUSH 10
OUT_CHAR (Draw\n)
-> [P,0,1,2,3,4,5,6,7,8] (original board)

PrintWin [P,0,1,2,3,4,5,6,7,8]:
PrintWin [P,0,1,2,3,4,5,6,7,8]: DONE!
PUSH 87
OUT_CHAR (W)
PUSH 105
Expand All @@ -369,7 +379,7 @@ PUSH 10
OUT_CHAR (Win for P!\n)
-> [P,0,1,2,3,4,5,6,7,8] (original board)

SwapPlayer [P1,0,1,2,3,4,5,6,7,8]:
SwapPlayer [P1,0,1,2,3,4,5,6,7,8]: DONE!
PUSH 79 -> [79,P1,0,1,2,3,4,5,6,7,8]
SUB -> [P1-79,0,1,2,3,4,5,6,7,8]
NOT -> [P1==79,0,1,2,3,4,5,6,7,8]
Expand All @@ -378,3 +388,22 @@ MUL -> [9 if P1==79 else 0,0,1,2,3,4,5,6,7,8]
PUSH 79 -> [79,9 if P1==79 else 0,0,1,2,3,4,5,6,7,8]
ADD -> [88 if P1==79 else 79,0,1,2,3,4,5,6,7,8]
-> [P2,0,1,2,3,4,5,6,7,8] (P1, P2 e (88,79) && P1 != P2)


PLAY_GAME:
INITIAL_SETUP -> [88,45,45,45,45,45,45,45,45,45]
PRINT_BOARD
PRINT_INPUT
IN_CHAR -> [V,88,45,45,45,45,45,45,45,45,45]
SET_NTH -> [88,45,45,45,88,45,45,45,45,45] (V = 3)
CHECK_WIN

IF 1 -> PRINT_WINNER -> SHOW_BOARD -> Done

IF 0 ->
CHECK_FULL
IF 1 -> PRINT_DRAW -> SHOW_BOARD -> Done

IF 0 ->
SWAP_PLAYER
PLAY_GAME
7 changes: 7 additions & 0 deletions tictactoe_piet/input1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
0
1
2
3
4
5
6
9 changes: 9 additions & 0 deletions tictactoe_piet/input2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
0
4
8
1
7
6
2
5
3
Binary file added tictactoe_piet/tictactoe.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b33c50a

Please sign in to comment.