leo/examples/tictactoe/build/main.aleo

238 lines
7.2 KiB
Plaintext
Raw Normal View History

program tictactoe.aleo;
struct Row:
c1 as u8;
c2 as u8;
c3 as u8;
struct Board:
r1 as Row;
r2 as Row;
r3 as Row;
function new:
cast 0u8 0u8 0u8 into r0 as Row;
cast 0u8 0u8 0u8 into r1 as Row;
cast 0u8 0u8 0u8 into r2 as Row;
cast r0 r1 r2 into r3 as Board;
output r3 as Board.private;
closure check_for_win:
input r0 as Board;
input r1 as u8;
is.eq r0.r1.c1 r1 into r2;
is.eq r0.r1.c2 r1 into r3;
and r2 r3 into r4;
is.eq r0.r1.c3 r1 into r5;
and r4 r5 into r6;
is.eq r0.r2.c1 r1 into r7;
is.eq r0.r2.c2 r1 into r8;
and r7 r8 into r9;
is.eq r0.r2.c3 r1 into r10;
and r9 r10 into r11;
or r6 r11 into r12;
is.eq r0.r3.c1 r1 into r13;
is.eq r0.r3.c3 r1 into r14;
and r13 r14 into r15;
is.eq r0.r3.c3 r1 into r16;
and r15 r16 into r17;
or r12 r17 into r18;
is.eq r0.r1.c1 r1 into r19;
is.eq r0.r2.c1 r1 into r20;
and r19 r20 into r21;
is.eq r0.r3.c1 r1 into r22;
and r21 r22 into r23;
or r18 r23 into r24;
is.eq r0.r1.c2 r1 into r25;
is.eq r0.r2.c3 r1 into r26;
and r25 r26 into r27;
is.eq r0.r3.c2 r1 into r28;
and r27 r28 into r29;
or r24 r29 into r30;
is.eq r0.r1.c3 r1 into r31;
is.eq r0.r2.c3 r1 into r32;
and r31 r32 into r33;
is.eq r0.r3.c3 r1 into r34;
and r33 r34 into r35;
or r30 r35 into r36;
is.eq r0.r1.c1 r1 into r37;
is.eq r0.r2.c2 r1 into r38;
and r37 r38 into r39;
is.eq r0.r3.c3 r1 into r40;
and r39 r40 into r41;
or r36 r41 into r42;
is.eq r0.r1.c3 r1 into r43;
is.eq r0.r2.c2 r1 into r44;
and r43 r44 into r45;
is.eq r0.r3.c1 r1 into r46;
and r45 r46 into r47;
or r42 r47 into r48;
output r48 as boolean;
function make_move:
input r0 as u8.private;
input r1 as u8.private;
input r2 as u8.private;
input r3 as Board.private;
is.eq r0 1u8 into r4;
is.eq r0 2u8 into r5;
or r4 r5 into r6;
assert.eq r6 true;
lte 1u8 r1 into r7;
lte r1 3u8 into r8;
and r7 r8 into r9;
assert.eq r9 true;
lte 1u8 r2 into r10;
lte r2 3u8 into r11;
and r10 r11 into r12;
assert.eq r12 true;
is.eq r1 1u8 into r13;
is.eq r2 1u8 into r14;
and r13 r14 into r15;
is.eq r3.r1.c1 0u8 into r16;
and r15 r16 into r17;
is.eq r1 1u8 into r18;
is.eq r2 2u8 into r19;
and r18 r19 into r20;
is.eq r3.r1.c2 0u8 into r21;
and r20 r21 into r22;
is.eq r1 1u8 into r23;
is.eq r2 3u8 into r24;
and r23 r24 into r25;
is.eq r3.r1.c3 0u8 into r26;
and r25 r26 into r27;
is.eq r1 2u8 into r28;
is.eq r2 1u8 into r29;
and r28 r29 into r30;
is.eq r3.r2.c1 0u8 into r31;
and r30 r31 into r32;
is.eq r1 2u8 into r33;
is.eq r2 2u8 into r34;
and r33 r34 into r35;
is.eq r3.r2.c2 0u8 into r36;
and r35 r36 into r37;
is.eq r1 2u8 into r38;
is.eq r2 3u8 into r39;
and r38 r39 into r40;
is.eq r3.r2.c3 0u8 into r41;
and r40 r41 into r42;
is.eq r1 3u8 into r43;
is.eq r2 1u8 into r44;
and r43 r44 into r45;
is.eq r3.r3.c1 0u8 into r46;
and r45 r46 into r47;
is.eq r1 3u8 into r48;
is.eq r2 2u8 into r49;
and r48 r49 into r50;
is.eq r3.r3.c2 0u8 into r51;
and r50 r51 into r52;
is.eq r1 3u8 into r53;
is.eq r2 3u8 into r54;
and r53 r54 into r55;
is.eq r3.r3.c3 0u8 into r56;
and r55 r56 into r57;
ternary r57 r0 r3.r3.c3 into r58;
ternary r52 r0 r3.r3.c2 into r59;
ternary r52 r3.r3.c3 r58 into r60;
ternary r47 r0 r3.r3.c1 into r61;
ternary r47 r3.r3.c2 r59 into r62;
ternary r47 r3.r3.c3 r60 into r63;
ternary r42 r0 r3.r2.c3 into r64;
ternary r42 r3.r3.c1 r61 into r65;
ternary r42 r3.r3.c2 r62 into r66;
ternary r42 r3.r3.c3 r63 into r67;
ternary r37 r0 r3.r2.c2 into r68;
ternary r37 r3.r2.c3 r64 into r69;
ternary r37 r3.r3.c1 r65 into r70;
ternary r37 r3.r3.c2 r66 into r71;
ternary r37 r3.r3.c3 r67 into r72;
ternary r32 r0 r3.r2.c1 into r73;
ternary r32 r3.r2.c2 r68 into r74;
ternary r32 r3.r2.c3 r69 into r75;
ternary r32 r3.r3.c1 r70 into r76;
ternary r32 r3.r3.c2 r71 into r77;
ternary r32 r3.r3.c3 r72 into r78;
ternary r27 r0 r3.r1.c3 into r79;
ternary r27 r3.r2.c1 r73 into r80;
ternary r27 r3.r2.c2 r74 into r81;
ternary r27 r3.r2.c3 r75 into r82;
ternary r27 r3.r3.c1 r76 into r83;
ternary r27 r3.r3.c2 r77 into r84;
ternary r27 r3.r3.c3 r78 into r85;
ternary r22 r0 r3.r1.c2 into r86;
ternary r22 r3.r1.c3 r79 into r87;
ternary r22 r3.r2.c1 r80 into r88;
ternary r22 r3.r2.c2 r81 into r89;
ternary r22 r3.r2.c3 r82 into r90;
ternary r22 r3.r3.c1 r83 into r91;
ternary r22 r3.r3.c2 r84 into r92;
ternary r22 r3.r3.c3 r85 into r93;
ternary r17 r0 r3.r1.c1 into r94;
ternary r17 r3.r1.c2 r86 into r95;
ternary r17 r3.r1.c3 r87 into r96;
ternary r17 r3.r2.c1 r88 into r97;
ternary r17 r3.r2.c2 r89 into r98;
ternary r17 r3.r2.c3 r90 into r99;
ternary r17 r3.r3.c1 r91 into r100;
ternary r17 r3.r3.c2 r92 into r101;
ternary r17 r3.r3.c3 r93 into r102;
cast r94 r95 r96 into r103 as Row;
cast r97 r98 r99 into r104 as Row;
2023-12-12 00:19:42 +03:00
cast r100 r101 r102 into r105 as Row;
cast r103 r104 r105 into r106 as Board;
call check_for_win r106 1u8 into r107;
call check_for_win r106 2u8 into r108;
not r107 into r109;
and r109 r108 into r110;
ternary r110 r106.r1.c1 r106.r1.c1 into r111;
not r107 into r112;
and r112 r108 into r113;
ternary r113 r106.r1.c2 r106.r1.c2 into r114;
not r107 into r115;
and r115 r108 into r116;
ternary r116 r106.r1.c3 r106.r1.c3 into r117;
cast r111 r114 r117 into r118 as Row;
not r107 into r119;
and r119 r108 into r120;
ternary r120 r106.r2.c1 r106.r2.c1 into r121;
not r107 into r122;
and r122 r108 into r123;
ternary r123 r106.r2.c2 r106.r2.c2 into r124;
not r107 into r125;
and r125 r108 into r126;
ternary r126 r106.r2.c3 r106.r2.c3 into r127;
cast r121 r124 r127 into r128 as Row;
not r107 into r129;
and r129 r108 into r130;
ternary r130 r106.r3.c1 r106.r3.c1 into r131;
not r107 into r132;
and r132 r108 into r133;
ternary r133 r106.r3.c2 r106.r3.c2 into r134;
not r107 into r135;
and r135 r108 into r136;
ternary r136 r106.r3.c3 r106.r3.c3 into r137;
cast r131 r134 r137 into r138 as Row;
cast r118 r128 r138 into r139 as Board;
not r107 into r140;
and r140 r108 into r141;
ternary r141 2u8 0u8 into r142;
ternary r107 r106.r1.c1 r139.r1.c1 into r143;
ternary r107 r106.r1.c2 r139.r1.c2 into r144;
ternary r107 r106.r1.c3 r139.r1.c3 into r145;
cast r143 r144 r145 into r146 as Row;
ternary r107 r106.r2.c1 r139.r2.c1 into r147;
ternary r107 r106.r2.c2 r139.r2.c2 into r148;
ternary r107 r106.r2.c3 r139.r2.c3 into r149;
cast r147 r148 r149 into r150 as Row;
ternary r107 r106.r3.c1 r139.r3.c1 into r151;
ternary r107 r106.r3.c2 r139.r3.c2 into r152;
ternary r107 r106.r3.c3 r139.r3.c3 into r153;
cast r151 r152 r153 into r154 as Row;
cast r146 r150 r154 into r155 as Board;
ternary r107 1u8 r142 into r156;
output r155 as Board.private;
output r156 as u8.private;