-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Heuristic Player and docs regarding arenas (#4)
* Add docs regarding arenas Signed-off-by: jparisu <[email protected]> * Add read the docs link in readme Signed-off-by: jparisu <[email protected]> * Add heuristic player Signed-off-by: jparisu <[email protected]> --------- Signed-off-by: jparisu <[email protected]>
- Loading branch information
Showing
5 changed files
with
140 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
:hidden: | ||
|
||
/src/getting_started | ||
/src/installation | ||
|
||
|
||
.. toctree:: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
|
||
from IArena.interfaces.IPosition import IPosition | ||
from IArena.interfaces.IMovement import IMovement | ||
from IArena.interfaces.IPlayer import IPlayer | ||
from IArena.utils.decorators import override, pure_virtual | ||
|
||
class HeuristicPlayer(IPlayer): | ||
|
||
@override | ||
def play( | ||
self, | ||
position: IPosition) -> IMovement: | ||
# Get rules of the game | ||
rules = position.get_rules() | ||
|
||
# Get all movements | ||
movements = rules.possible_movements(position) | ||
|
||
# Calculate heuristic for all possible positions from every possible movement | ||
values = [ | ||
self.heuristic( | ||
rules.next_position(movement, position)) | ||
for movement | ||
in movements] | ||
|
||
# Return the best movement | ||
return movements[values.index(min(values))] | ||
|
||
@pure_virtual | ||
def heuristic( | ||
self, | ||
position: IPosition) -> float: | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters