|
| 1 | +program tictactoe.aleo; |
| 2 | + |
| 3 | +struct Row: |
| 4 | + c1 as u8; |
| 5 | + c2 as u8; |
| 6 | + c3 as u8; |
| 7 | + |
| 8 | +struct Board: |
| 9 | + r1 as Row; |
| 10 | + r2 as Row; |
| 11 | + r3 as Row; |
| 12 | + |
| 13 | + |
| 14 | +function new: |
| 15 | + cast 0u8 0u8 0u8 into r0 as Row; |
| 16 | + cast 0u8 0u8 0u8 into r1 as Row; |
| 17 | + cast 0u8 0u8 0u8 into r2 as Row; |
| 18 | + cast r0 r1 r2 into r3 as Board; |
| 19 | + output r3 as Board.private; |
| 20 | + |
| 21 | + |
| 22 | +closure check_for_win: |
| 23 | + input r0 as Board; |
| 24 | + input r1 as u8; |
| 25 | + is.eq r0.r1.c1 r1 into r2; |
| 26 | + is.eq r0.r1.c2 r1 into r3; |
| 27 | + and r2 r3 into r4; |
| 28 | + is.eq r0.r1.c3 r1 into r5; |
| 29 | + and r4 r5 into r6; |
| 30 | + is.eq r0.r2.c1 r1 into r7; |
| 31 | + is.eq r0.r2.c2 r1 into r8; |
| 32 | + and r7 r8 into r9; |
| 33 | + is.eq r0.r2.c3 r1 into r10; |
| 34 | + and r9 r10 into r11; |
| 35 | + or r6 r11 into r12; |
| 36 | + is.eq r0.r3.c1 r1 into r13; |
| 37 | + is.eq r0.r3.c3 r1 into r14; |
| 38 | + and r13 r14 into r15; |
| 39 | + is.eq r0.r3.c3 r1 into r16; |
| 40 | + and r15 r16 into r17; |
| 41 | + or r12 r17 into r18; |
| 42 | + is.eq r0.r1.c1 r1 into r19; |
| 43 | + is.eq r0.r2.c1 r1 into r20; |
| 44 | + and r19 r20 into r21; |
| 45 | + is.eq r0.r3.c1 r1 into r22; |
| 46 | + and r21 r22 into r23; |
| 47 | + or r18 r23 into r24; |
| 48 | + is.eq r0.r1.c2 r1 into r25; |
| 49 | + is.eq r0.r2.c3 r1 into r26; |
| 50 | + and r25 r26 into r27; |
| 51 | + is.eq r0.r3.c2 r1 into r28; |
| 52 | + and r27 r28 into r29; |
| 53 | + or r24 r29 into r30; |
| 54 | + is.eq r0.r1.c3 r1 into r31; |
| 55 | + is.eq r0.r2.c3 r1 into r32; |
| 56 | + and r31 r32 into r33; |
| 57 | + is.eq r0.r3.c3 r1 into r34; |
| 58 | + and r33 r34 into r35; |
| 59 | + or r30 r35 into r36; |
| 60 | + is.eq r0.r1.c1 r1 into r37; |
| 61 | + is.eq r0.r2.c2 r1 into r38; |
| 62 | + and r37 r38 into r39; |
| 63 | + is.eq r0.r3.c3 r1 into r40; |
| 64 | + and r39 r40 into r41; |
| 65 | + or r36 r41 into r42; |
| 66 | + is.eq r0.r1.c3 r1 into r43; |
| 67 | + is.eq r0.r2.c2 r1 into r44; |
| 68 | + and r43 r44 into r45; |
| 69 | + is.eq r0.r3.c1 r1 into r46; |
| 70 | + and r45 r46 into r47; |
| 71 | + or r42 r47 into r48; |
| 72 | + output r48 as boolean; |
| 73 | + |
| 74 | + |
| 75 | +function make_move: |
| 76 | + input r0 as u8.private; |
| 77 | + input r1 as u8.private; |
| 78 | + input r2 as u8.private; |
| 79 | + input r3 as Board.private; |
| 80 | + is.eq r0 1u8 into r4; |
| 81 | + is.eq r0 2u8 into r5; |
| 82 | + or r4 r5 into r6; |
| 83 | + assert.eq r6 true; |
| 84 | + lte 1u8 r1 into r7; |
| 85 | + lte r1 3u8 into r8; |
| 86 | + and r7 r8 into r9; |
| 87 | + assert.eq r9 true; |
| 88 | + lte 1u8 r2 into r10; |
| 89 | + lte r2 3u8 into r11; |
| 90 | + and r10 r11 into r12; |
| 91 | + assert.eq r12 true; |
| 92 | + is.eq r1 1u8 into r13; |
| 93 | + is.eq r2 1u8 into r14; |
| 94 | + and r13 r14 into r15; |
| 95 | + is.eq r3.r1.c1 0u8 into r16; |
| 96 | + and r15 r16 into r17; |
| 97 | + is.eq r1 1u8 into r18; |
| 98 | + is.eq r2 2u8 into r19; |
| 99 | + and r18 r19 into r20; |
| 100 | + is.eq r3.r1.c2 0u8 into r21; |
| 101 | + and r20 r21 into r22; |
| 102 | + is.eq r1 1u8 into r23; |
| 103 | + is.eq r2 3u8 into r24; |
| 104 | + and r23 r24 into r25; |
| 105 | + is.eq r3.r1.c3 0u8 into r26; |
| 106 | + and r25 r26 into r27; |
| 107 | + is.eq r1 2u8 into r28; |
| 108 | + is.eq r2 1u8 into r29; |
| 109 | + and r28 r29 into r30; |
| 110 | + is.eq r3.r2.c1 0u8 into r31; |
| 111 | + and r30 r31 into r32; |
| 112 | + is.eq r1 2u8 into r33; |
| 113 | + is.eq r2 2u8 into r34; |
| 114 | + and r33 r34 into r35; |
| 115 | + is.eq r3.r2.c2 0u8 into r36; |
| 116 | + and r35 r36 into r37; |
| 117 | + is.eq r1 2u8 into r38; |
| 118 | + is.eq r2 3u8 into r39; |
| 119 | + and r38 r39 into r40; |
| 120 | + is.eq r3.r2.c3 0u8 into r41; |
| 121 | + and r40 r41 into r42; |
| 122 | + is.eq r1 3u8 into r43; |
| 123 | + is.eq r2 1u8 into r44; |
| 124 | + and r43 r44 into r45; |
| 125 | + is.eq r3.r3.c1 0u8 into r46; |
| 126 | + and r45 r46 into r47; |
| 127 | + is.eq r1 3u8 into r48; |
| 128 | + is.eq r2 2u8 into r49; |
| 129 | + and r48 r49 into r50; |
| 130 | + is.eq r3.r3.c2 0u8 into r51; |
| 131 | + and r50 r51 into r52; |
| 132 | + is.eq r1 3u8 into r53; |
| 133 | + is.eq r2 3u8 into r54; |
| 134 | + and r53 r54 into r55; |
| 135 | + is.eq r3.r3.c3 0u8 into r56; |
| 136 | + and r55 r56 into r57; |
| 137 | + ternary r57 r0 r3.r3.c3 into r58; |
| 138 | + ternary r52 r0 r3.r3.c2 into r59; |
| 139 | + ternary r52 r3.r3.c3 r58 into r60; |
| 140 | + ternary r47 r0 r3.r3.c1 into r61; |
| 141 | + ternary r47 r3.r3.c2 r59 into r62; |
| 142 | + ternary r47 r3.r3.c3 r60 into r63; |
| 143 | + ternary r42 r0 r3.r2.c3 into r64; |
| 144 | + ternary r42 r3.r3.c1 r61 into r65; |
| 145 | + ternary r42 r3.r3.c2 r62 into r66; |
| 146 | + ternary r42 r3.r3.c3 r63 into r67; |
| 147 | + ternary r37 r0 r3.r2.c2 into r68; |
| 148 | + ternary r37 r3.r2.c3 r64 into r69; |
| 149 | + ternary r37 r3.r3.c1 r65 into r70; |
| 150 | + ternary r37 r3.r3.c2 r66 into r71; |
| 151 | + ternary r37 r3.r3.c3 r67 into r72; |
| 152 | + ternary r32 r0 r3.r2.c1 into r73; |
| 153 | + ternary r32 r3.r2.c2 r68 into r74; |
| 154 | + ternary r32 r3.r2.c3 r69 into r75; |
| 155 | + ternary r32 r3.r3.c1 r70 into r76; |
| 156 | + ternary r32 r3.r3.c2 r71 into r77; |
| 157 | + ternary r32 r3.r3.c3 r72 into r78; |
| 158 | + ternary r27 r0 r3.r1.c3 into r79; |
| 159 | + ternary r27 r3.r2.c1 r73 into r80; |
| 160 | + ternary r27 r3.r2.c2 r74 into r81; |
| 161 | + ternary r27 r3.r2.c3 r75 into r82; |
| 162 | + ternary r27 r3.r3.c1 r76 into r83; |
| 163 | + ternary r27 r3.r3.c2 r77 into r84; |
| 164 | + ternary r27 r3.r3.c3 r78 into r85; |
| 165 | + ternary r22 r0 r3.r1.c2 into r86; |
| 166 | + ternary r22 r3.r1.c3 r79 into r87; |
| 167 | + ternary r22 r3.r2.c1 r80 into r88; |
| 168 | + ternary r22 r3.r2.c2 r81 into r89; |
| 169 | + ternary r22 r3.r2.c3 r82 into r90; |
| 170 | + ternary r22 r3.r3.c1 r83 into r91; |
| 171 | + ternary r22 r3.r3.c2 r84 into r92; |
| 172 | + ternary r22 r3.r3.c3 r85 into r93; |
| 173 | + ternary r17 r0 r3.r1.c1 into r94; |
| 174 | + ternary r17 r3.r1.c2 r86 into r95; |
| 175 | + ternary r17 r3.r1.c3 r87 into r96; |
| 176 | + ternary r17 r3.r2.c1 r88 into r97; |
| 177 | + ternary r17 r3.r2.c2 r89 into r98; |
| 178 | + ternary r17 r3.r2.c3 r90 into r99; |
| 179 | + ternary r17 r3.r3.c1 r91 into r100; |
| 180 | + ternary r17 r3.r3.c2 r92 into r101; |
| 181 | + ternary r17 r3.r3.c3 r93 into r102; |
| 182 | + cast r94 r95 r96 into r103 as Row; |
| 183 | + cast r97 r98 r99 into r104 as Row; |
| 184 | + cast r100 r101 r102 into r105 as Row; |
| 185 | + cast r103 r104 r105 into r106 as Board; |
| 186 | + call check_for_win r106 1u8 into r107; |
| 187 | + call check_for_win r106 2u8 into r108; |
| 188 | + not r107 into r109; |
| 189 | + and r109 r108 into r110; |
| 190 | + ternary r110 r106.r1.c1 r106.r1.c1 into r111; |
| 191 | + not r107 into r112; |
| 192 | + and r112 r108 into r113; |
| 193 | + ternary r113 r106.r1.c2 r106.r1.c2 into r114; |
| 194 | + not r107 into r115; |
| 195 | + and r115 r108 into r116; |
| 196 | + ternary r116 r106.r1.c3 r106.r1.c3 into r117; |
| 197 | + cast r111 r114 r117 into r118 as Row; |
| 198 | + not r107 into r119; |
| 199 | + and r119 r108 into r120; |
| 200 | + ternary r120 r106.r2.c1 r106.r2.c1 into r121; |
| 201 | + not r107 into r122; |
| 202 | + and r122 r108 into r123; |
| 203 | + ternary r123 r106.r2.c2 r106.r2.c2 into r124; |
| 204 | + not r107 into r125; |
| 205 | + and r125 r108 into r126; |
| 206 | + ternary r126 r106.r2.c3 r106.r2.c3 into r127; |
| 207 | + cast r121 r124 r127 into r128 as Row; |
| 208 | + not r107 into r129; |
| 209 | + and r129 r108 into r130; |
| 210 | + ternary r130 r106.r3.c1 r106.r3.c1 into r131; |
| 211 | + not r107 into r132; |
| 212 | + and r132 r108 into r133; |
| 213 | + ternary r133 r106.r3.c2 r106.r3.c2 into r134; |
| 214 | + not r107 into r135; |
| 215 | + and r135 r108 into r136; |
| 216 | + ternary r136 r106.r3.c3 r106.r3.c3 into r137; |
| 217 | + cast r131 r134 r137 into r138 as Row; |
| 218 | + cast r118 r128 r138 into r139 as Board; |
| 219 | + not r107 into r140; |
| 220 | + and r140 r108 into r141; |
| 221 | + ternary r141 2u8 0u8 into r142; |
| 222 | + ternary r107 r106.r1.c1 r139.r1.c1 into r143; |
| 223 | + ternary r107 r106.r1.c2 r139.r1.c2 into r144; |
| 224 | + ternary r107 r106.r1.c3 r139.r1.c3 into r145; |
| 225 | + cast r143 r144 r145 into r146 as Row; |
| 226 | + ternary r107 r106.r2.c1 r139.r2.c1 into r147; |
| 227 | + ternary r107 r106.r2.c2 r139.r2.c2 into r148; |
| 228 | + ternary r107 r106.r2.c3 r139.r2.c3 into r149; |
| 229 | + cast r147 r148 r149 into r150 as Row; |
| 230 | + ternary r107 r106.r3.c1 r139.r3.c1 into r151; |
| 231 | + ternary r107 r106.r3.c2 r139.r3.c2 into r152; |
| 232 | + ternary r107 r106.r3.c3 r139.r3.c3 into r153; |
| 233 | + cast r151 r152 r153 into r154 as Row; |
| 234 | + cast r146 r150 r154 into r155 as Board; |
| 235 | + ternary r107 1u8 r142 into r156; |
| 236 | + output r155 as Board.private; |
| 237 | + output r156 as u8.private; |
0 commit comments