Created
June 17, 2020 19:36
-
-
Save kenota/5ad7b1290927c7e368109814b21859a7 to your computer and use it in GitHub Desktop.
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
module Player exposing (takeTurn) | |
import Warrior exposing (..) | |
import Warrior.Direction exposing (..) | |
import Warrior.History exposing (..) | |
import Warrior.Map exposing (..) | |
import Warrior.Map.Tile exposing (..) | |
takeTurn : Warrior -> Map -> History -> Warrior.Action | |
takeTurn warrior map history = | |
let | |
lastAction = | |
Maybe.withDefault Wait (List.head (previousActions warrior history)) | |
in | |
if canMove warrior Right map && lastAction /= Move Left then | |
Move Right | |
else if canMove warrior Down map && lastAction /= Move Up then | |
Move Down | |
else if canMove warrior Left map then | |
Move Left | |
else | |
Move Up | |
canMove : Warrior -> Direction -> Map -> Bool | |
canMove warrior direction map = | |
let | |
side = | |
List.head (look direction warrior map) | |
in | |
case side of | |
Just t -> | |
if canMoveOnto (Tuple.second t) then | |
True | |
else | |
False | |
Nothing -> | |
False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment