arun
Abhinav Sarkar 2015-07-10 01:01:00 +05:30
parent 8b4f606469
commit 75a7c0ce70
1 changed files with 3 additions and 5 deletions

View File

@ -41,7 +41,7 @@ checkTrail GameMap{..} trail =
else (trail', PlayerDead) else (trail', PlayerDead)
stepGame :: Game -> InEvent -> (Game, [OutEvent]) stepGame :: Game -> InEvent -> (Game, [OutEvent])
stepGame game@Game{gameMap = gameMap@GameMap{..}, ..} inEvent = stepGame' inEvent stepGame game@Game{gameMap = gameMap@GameMap{..}, ..} = stepGame'
where where
stepGame' (InPlayerTurnLeft playerId) = stepTurnEvent playerId $ moveAfterTurn leftTurn stepGame' (InPlayerTurnLeft playerId) = stepTurnEvent playerId $ moveAfterTurn leftTurn
stepGame' (InPlayerTurnRight playerId) = stepTurnEvent playerId $ moveAfterTurn rightTurn stepGame' (InPlayerTurnRight playerId) = stepTurnEvent playerId $ moveAfterTurn rightTurn
@ -66,10 +66,8 @@ stepGame game@Game{gameMap = gameMap@GameMap{..}, ..} inEvent = stepGame' inEven
foldl' (flip Set.insert) gameMapBlockedPoints trail } foldl' (flip Set.insert) gameMapBlockedPoints trail }
game' = game { gamePlayers = Map.insert playerId player' gamePlayers game' = game { gamePlayers = Map.insert playerId player' gamePlayers
, gameMap = gameMap' } , gameMap = gameMap' }
outEvents = [OutPlayerPosition playerId pos' dir'] ++ outEvents = OutPlayerPosition playerId pos' dir' :
(if playerState /= playerState' [OutPlayerStateChange playerId playerState' | playerState /= playerState']
then [OutPlayerStateChange playerId playerState']
else [])
in (game', outEvents) in (game', outEvents)
score (x1, y1) (x2, y2) = abs (x1 - x2) + abs (y1 - y2) score (x1, y1) (x2, y2) = abs (x1 - x2) + abs (y1 - y2)