diff --git a/.github/workflows/piet.yaml b/.github/workflows/piet.yaml index 821da5d..136f967 100644 --- a/.github/workflows/piet.yaml +++ b/.github/workflows/piet.yaml @@ -1,6 +1,6 @@ # This workflow will run stuff on the piet version of tictactoe. -name: tpiet +name: piet on: push: @@ -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 diff --git a/README.md b/README.md index d9dbeb5..3eed628 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/_typos.toml b/_typos.toml index 15fd62b..2058ccf 100644 --- a/_typos.toml +++ b/_typos.toml @@ -3,6 +3,9 @@ ba = "ba" # Clojure settings. edn = "edn" +# From piet version +Inpu = "Inpu" +fo = "fo" [default] diff --git a/tictactoe_piet/.gitignore b/tictactoe_piet/.gitignore new file mode 100644 index 0000000..c66796c --- /dev/null +++ b/tictactoe_piet/.gitignore @@ -0,0 +1 @@ +aux_mat/ diff --git a/tictactoe_piet/PietLogic.txt b/tictactoe_piet/PietLogic.txt index 9509df7..cfffdeb 100644 --- a/tictactoe_piet/PietLogic.txt +++ b/tictactoe_piet/PietLogic.txt @@ -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] @@ -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] @@ -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] @@ -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] @@ -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] @@ -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,P,0,1,2,3,4,5,6,7,8,X,Y] -ROLL -> [P,0,1,2,3,4,5,6,7,8,Z==P,X,Y] +GetNth -> [VZ,P,0,1,2,3,4,5,6,7,8,X,Y] +EqualToPlayer -> [VZ==P,P,0,1,2,3,4,5,6,7,8,X,Y] +PUSH 11 -> [11,VZ==P,P,0,1,2,3,4,5,6,7,8,X,Y] +PUSH 1 -> [1,11,VZ==P,P,0,1,2,3,4,5,6,7,8,X,Y] +ROLL -> [P,0,1,2,3,4,5,6,7,8,VZ==P,X,Y] PUSH 13 -> [13,P,0,1,2,3,4,5,6,7,8,Z==P,X,Y] PUSH 12 -> [12,13,P,0,1,2,3,4,5,6,7,8,Z==P,X,Y] ROLL -> [Y,P,0,1,2,3,4,5,6,7,8,Z==P,X] -EqualToPlayer -> [Y==P,P,0,1,2,3,4,5,6,7,8,Z==P,X] -PUSH 11 -> [11,Y==P,P,0,1,2,3,4,5,6,7,8,Z==P,X] -PUSH 1 -> [1,11,Y==P,P,0,1,2,3,4,5,6,7,8,Z==P,X] -ROLL -> [P,0,1,2,3,4,5,6,7,8,Y==P,Z==P,X] - -PUSH 13 -> [13,P,0,1,2,3,4,5,6,7,8,Y==P,Z==P,X] -PUSH 12 -> [12,13,P,0,1,2,3,4,5,6,7,8,Y==P,Z==P,X] -ROLL -> [X,P,0,1,2,3,4,5,6,7,8,Y==P,Z==P] -EqualToPlayer -> [X==P,P,0,1,2,3,4,5,6,7,8,Y==P,Z==P] - -PUSH 13 -> [13,X==P,P,0,1,2,3,4,5,6,7,8,Y==P,Z==P] -PUSH 11 -> [11,13,X==P,P,0,1,2,3,4,5,6,7,8,Y==P,Z==P] -ROLL -> [Y==P,Z==P,X==P,P,0,1,2,3,4,5,6,7,8] -ADD -> [Y==P + Z==P,X==P,P,0,1,2,3,4,5,6,7,8] -ADD -> [Y==P + Z==P + X==P,P,0,1,2,3,4,5,6,7,8] -PUSH 3 -> [3,Y==P + Z==P + X==P,P,0,1,2,3,4,5,6,7,8] -SUB -> [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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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] @@ -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 diff --git a/tictactoe_piet/input1.txt b/tictactoe_piet/input1.txt new file mode 100644 index 0000000..09c277a --- /dev/null +++ b/tictactoe_piet/input1.txt @@ -0,0 +1,7 @@ +0 +1 +2 +3 +4 +5 +6 diff --git a/tictactoe_piet/input2.txt b/tictactoe_piet/input2.txt new file mode 100644 index 0000000..25d3210 --- /dev/null +++ b/tictactoe_piet/input2.txt @@ -0,0 +1,9 @@ +0 +4 +8 +1 +7 +6 +2 +5 +3 diff --git a/tictactoe_piet/tictactoe.png b/tictactoe_piet/tictactoe.png new file mode 100644 index 0000000..9a1c6e6 Binary files /dev/null and b/tictactoe_piet/tictactoe.png differ