Skip to content

Commit

Permalink
Some cleanup of the generic version
Browse files Browse the repository at this point in the history
  • Loading branch information
JanEricNitschke committed Jul 23, 2023
1 parent 065b879 commit 38bc9f2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 14 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ tictactoe_ruby/*.gem
# Compiled class file
*.class

/fibonacci

tictactoe_java/*.jar

tictactoe_ada/obj/
Expand Down
19 changes: 6 additions & 13 deletions tictactoe_generic/tictactoe_generic.gen
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,8 @@ class TicTacToe {

check_win_condition(player, win_condition) {
var result = ConditionResult();
var spot;
for (var i = 0; i < len(win_condition); i += 1) {
spot = win_condition[i];
const spot = win_condition[i];
if this.board[spot] == player {
result.spots_done += 1;
}
Expand All @@ -64,9 +63,8 @@ class TicTacToe {
}

is_player_win(player) {
var result;
for (var i = 0; i < len(this.win_conditions); i += 1) {
result = this.check_win_condition(player, this.win_conditions[i]);
const result = this.check_win_condition(player, this.win_conditions[i]);
if result.spots_done == 3 {
return true;
}
Expand Down Expand Up @@ -100,11 +98,9 @@ class TicTacToe {
print("Player " + player + " turn.");
this.show_board();

var spot;
var valid_input = false;
var user_input;
until valid_input {
user_input = input("Where to make your next move? [0-8]");
const user_input = input("Where to make your next move? [0-8]");
unless is_int(user_input) {
print("ERROR: Input must be a valid integer!");
continue;
Expand Down Expand Up @@ -134,11 +130,9 @@ class TicTacToe {
}

get_winning_move(player) {
var result;
var condition;
for (var i = 0; i < len(this.win_conditions); i += 1) {
condition = this.win_conditions[i];
result = this.check_win_condition(player, condition);
const condition = this.win_conditions[i];
const result = this.check_win_condition(player, condition);
if (result.spots_done == 2 and len(result.spots_open) == 1) {
return Move(result.spots_open[0], 1);
}
Expand Down Expand Up @@ -244,14 +238,13 @@ class TicTacToe {

get_ai_strength() {
var strength;
var response;
print("AI strength settings:");
print("1: Easy");
print("2: Medium");
print("3: Hard");
print("4: Impossible");
until [1, 2, 3, 4].contains(strength) {
response = input("How strong should the AI be? [1 - 4]");
const response = input("How strong should the AI be? [1 - 4]");
unless is_int(response) {
print("Bad choice");
}
Expand Down
2 changes: 1 addition & 1 deletion tictactoe_python/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
exclude: docs/
exclude: docs/|fibonacci/
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
Expand Down

0 comments on commit 38bc9f2

Please sign in to comment.