Skip to content

Commit

Permalink
added new checkwinners
Browse files Browse the repository at this point in the history
  • Loading branch information
OwnerOfJK committed Nov 18, 2023
1 parent 1e38164 commit 1f03d95
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 4 deletions.
64 changes: 60 additions & 4 deletions contracts/src/app.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,66 @@ mod tictactoe_actions {
) -> u8 {
let mut player1: u8 = 1;
let mut result: u8 = 0;
if *game_array.at(0) == player1
&& *game_array.at(1) == player1
&& *game_array.at(2) == player1 {
result = 1;
// if *game_array.at(0) == player1
// && *game_array.at(1) == player1
// && *game_array.at(2) == player1 {
// result = 1;
// }
let mut index = 0;
let game_array2 = game_array.clone();

loop {
if index == 3 {
break;
}
// Horizontal check
if *game_array2.at(3*index) == *game_array2.at(3*index + 1)
&& *game_array2.at(3*index) == *game_array2.at(3*index + 2)
&& *game_array2.at(3*index) != 0 {
result = *game_array2.at(3*index);
}

// Vertical check
if *game_array2.at(index) == *game_array2.at(index + 3)
&& *game_array2.at(index) == *game_array2.at(index + 6)
&& *game_array2.at(index) != 0 {
result = *game_array2.at(3*index);
}
index = index + 1 ;
};

let game_array3 = game_array.clone();

if *game_array3.at(0) == *game_array3.at(4)
&& *game_array3.at(0) == *game_array3.at(8)
&& *game_array3.at(0) != 0 {
result = *game_array3.at(0);
}

if *game_array3.at(2) == *game_array3.at(4)
&& *game_array3.at(2) == *game_array3.at(6)
&& *game_array3.at(2) != 0 {
result = *game_array3.at(2);
}

if result == 0 {
let mut zero_found:bool = false;
let mut index = 0;
loop {
if index == 8 {
break;
}
if *game_array3.at(index) == 0 {
zero_found = true;
}
index += 1;
};
if zero_found {
result = 0;
}
else {
result = 3;
}
}
result
}
Expand Down
1 change: 1 addition & 0 deletions contracts/src/tests.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,5 @@ mod tests {

'Passed test'.print();
}

}

0 comments on commit 1f03d95

Please sign in to comment.