Skip to content

Commit

Permalink
Merge pull request #204 from joshuafolkken/203-position-priority
Browse files Browse the repository at this point in the history
position priority #203
  • Loading branch information
joshuafolkken authored Nov 3, 2024
2 parents 6401c7e + eb5061f commit c42849e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ config_version=5
[application]

config/name="Tic Tac Toe"
config/version="0.60.0"
config/version="0.61.0"
run/main_scene="res://scenes/main.tscn"
config/features=PackedStringArray("4.3", "GL Compatibility")
config/icon="res://icon.svg"
Expand Down
9 changes: 9 additions & 0 deletions src/lib/ai_strategy/minimax_strategy.gd
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,15 @@ func choose_move() -> BoardPosition:
_nodes_evaluated = 0

var available_positions := _board.get_empty_positions()

if available_positions.size() >= BoardPosition.MAX_SIZE ** 2 - 1:
available_positions.sort_custom(
func(a: BoardPosition, b: BoardPosition) -> int:
return a.get_priority() > b.get_priority()
)

return available_positions[0]

var best_score := INITIAL_ALPHA
var best_position := available_positions[0]
var cell_status := CellStatus.from_game_player(_current_player)
Expand Down
10 changes: 10 additions & 0 deletions src/lib/board_position.gd
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,13 @@ func to_index() -> int:

func is_valid() -> bool:
return _row_index != INVALID_INDEX and _col_index != INVALID_INDEX


func get_priority() -> int:
if _row_index == 1 and _col_index == 1:
return 2

if (_row_index == 0 or _row_index == 2) and (_col_index == 0 or _col_index == 2):
return 1

return 0

0 comments on commit c42849e

Please sign in to comment.