Skip to content

Instantly share code, notes, and snippets.

@kenota
Created June 17, 2020 19:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kenota/5ad7b1290927c7e368109814b21859a7 to your computer and use it in GitHub Desktop.
Save kenota/5ad7b1290927c7e368109814b21859a7 to your computer and use it in GitHub Desktop.
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