Skip to content

Commit

Permalink
Fighting is working great. Test behavior now bites.
Browse files Browse the repository at this point in the history
Signed-off-by: Richard Minerich <richard.minerich@gmail.com>
  • Loading branch information
Rickasaurus committed May 17, 2012
1 parent 70b8baf commit 38aadd8
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 26 deletions.
47 changes: 25 additions & 22 deletions AntsEverywhereApp/TestAntBehavior.fs
Original file line number Diff line number Diff line change
Expand Up @@ -66,27 +66,30 @@ type TestAntBehavior() =
let minPhero = List.minBy (fun (node: AntCellView) -> node.FriendlyPheromoneQuantity)
let noAnts = List.filter (fun (node: AntCellView) -> node.ContainsAnt)

// [snippet:Simple Pheromone-Using Ant Colony AI]
match me with
| HasFood
| HasMaxFood ->
match locations.Cells with
| NearHome homeCells ->
match homeCells with
| CanDrop dropCells -> DropFood dropCells.Head
// [snippet:Simple Pheromone-Using Ant Colony AI]
match locations.EnemyCells with
| h :: rest -> Attack h
| [] ->
match me with
| HasFood
| HasMaxFood ->
match locations.Cells with
| NearHome homeCells ->
match homeCells with
| CanDrop dropCells -> DropFood dropCells.Head
| HasNoAnt noAntCells -> Move (List.random noAntCells)
| _ -> Nothing
| AwayFromHome allCells ->
match here.FriendlyPheromoneQuantity with
| n when n < 20 -> DropPheromone (here, 100 - n)
| _ -> match allCells with
| HasNoAnt noAnts when rnd.Next(0, 3) = 0 -> Move (List.random noAnts)
| ShortestDistanceWithNoAnt node -> Move node
| _ -> Nothing
| HasNoFood ->
match locations.Cells with
| HasNoAnt noAnts when rnd.Next(0, 3) = 0 -> Move (List.random noAnts)
| HasUnownedFood foodCells -> TakeFood (maxFood foodCells)
| HasPheromonesAndNoAnt pheroCells -> Move (minPhero pheroCells)
| HasNoAnt noAntCells -> Move (List.random noAntCells)
| _ -> Nothing
| AwayFromHome allCells ->
match here.FriendlyPheromoneQuantity with
| n when n < 20 -> DropPheromone (here, 100 - n)
| _ -> match allCells with
| HasNoAnt noAnts when rnd.Next(0, 3) = 0 -> Move (List.random noAnts)
| ShortestDistanceWithNoAnt node -> Move node
| _ -> Nothing
| HasNoFood ->
match locations.Cells with
| HasNoAnt noAnts when rnd.Next(0, 3) = 0 -> Move (List.random noAnts)
| HasUnownedFood foodCells -> TakeFood (maxFood foodCells)
| HasPheromonesAndNoAnt pheroCells -> Move (minPhero pheroCells)
| HasNoAnt noAntCells -> Move (List.random noAntCells)
| _ -> Nothing
4 changes: 2 additions & 2 deletions AntsEverywhereLib/Types.fs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ module AntsEverywhereLib.Types

open System

let xSize = 30
let ySize = 30
let xSize = 15
let ySize = 15
let nestSize = 3
let maxTotalFoodPerSquare = 200
let minGeneratedFoodPerSquare = 20
Expand Down
4 changes: 2 additions & 2 deletions AntsEverywhereLib/World.fs
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ let getAntActions (bBehave: IAntBehavior) (rBehave: IAntBehavior) (views: (Ant *
| AntColor.Black -> bBehave
| AntColor.Red -> rBehave
views |> List.map (fun (ant, cell, antView, nest) -> let behavior = getAntBehavior ant in
cell, behavior.Behave (AntView ant) (AntCellView (cell, ant, nest)) (AntNearbyView.FromWorldCells antView ant nest))
cell, behavior.Behave (AntView(ant, ant)) (AntCellView (cell, ant, nest)) (AntNearbyView.FromWorldCells antView ant nest))
let buildDependentTransaction (expectedCells: WorldCell list) actions =
let predicate = (fun (world: TheWorld) -> expectedCells |> List.forall (fun (cell: WorldCell) -> (Map.find cell.Id world) = cell))
let action = (fun (iworld: TheWorld) ->
List.fold (fun (cworld: TheWorld) (id, action) ->
Map.add id (action cworld.[id]) cworld) iworld actions)
predicate, action
predicate, action

let dropPheromonesInTargetCell antColor quantity target =
let newValue = max (target.Pheromones.[antColor] + quantity) maxCellPheromoneQuantity in
Expand Down

0 comments on commit 38aadd8

Please sign in to comment.