[SOLVED] CS {-

$25

File Name: CS_{-.zip
File Size: 47.1 KB

5/5 - (1 vote)

{-
Module: Dumb.

Implementation of a player that simply picks a random valid step.
-}
module Players.Dumb where

import Data.List

import Types
import Constants
import Action
import Board
import Player
import Cell

All possible steps.
allSteps :: [Step]
allSteps = [(c1, c2) | c1<-allCells, c2<-allCells]whereallCells = [(i, j) | i<-allColumns, j<-allRows]– Select random valid move.dumbAction :: Board -> [Player] -> String -> Int -> Maybe Action
dumbAction b (p:ps) _ r = if validMoves == [] then Nothing else Just (validMoves!!randomIdx)
where
validMoves = [Move mv | mv<-allSteps, (canMove p ps mv) && (validStep b mv)]randomIdx = r `mod` (length validMoves)– Make player in the usual way using ‘dumbAction’.makeDumbPlayer :: String -> Cell -> Int -> [Cell] -> Player
makeDumbPlayer n c rws wps = Player {
name = n,
turn = 1,
currentCell = c,
remainingWalls = rws,
winningPositions = wps,
isHuman = False,
chooseAction = dumbAction }

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[SOLVED] CS {-
$25