Commit bdb1df95 authored by Jorn W. Janneck's avatar Jorn W. Janneck

added the submissions to the 2019 competition

parent 7fec459e
(ns amoebas.competition2019.Amoeboiz.core
(:use amoebas.defs amoebas.lib amoebas.run amoebas.examples)
)
(defn core
[soldier-function soldier-behaviour border-function border-behaviour middle-behaviour]
(fn [energy health species env data]
(if (soldier-function energy health species env data)
(soldier-behaviour energy health species env data)
(if (border-function energy health species env data)
(border-behaviour energy health species env data)
(middle-behaviour energy health species env data)
)
)
)
)
(defn soldier-if-enemies-nearby
[energy health species env data]
(< 0 (count (hostiles species Environment env)))
)
(defn soldier-divide-attack
[divideUntil divide-behaviour attack-behaviour]
(fn [energy health species env data]
(if (> divideUntil (count (friendlies species Environment env)))
(divide-behaviour energy health species env data)
(if (> 10 energy)
(divide-behaviour energy health species env data) ;Fuel
(attack-behaviour energy health species env data)
)
)
)
)
(defn divide-and-fuel [divide-energy fuel-targeter]
(fn [energy health species env data]
(if (< energy divide-energy)
(if (< 9 (:fuel (env 0 0)))
{:cmd :rest}
(fuel-targeter energy health species env data :move)
)
(fuel-targeter energy health species env data :divide)
)
)
)
(defn goto-highest-fuel
[energy health species env data command]
(def goto (last (sort-by #(:fuel (env (Neighbors %))) (empty-neighbors env))))
(if goto
{:cmd command :dir goto}
{:cmd :rest}
)
)
(defn goto-highest-fuel-if-greater-than
[limit]
(fn
[energy health species env data command]
(def goto (last (sort-by #(:fuel (env (Neighbors %))) (empty-neighbors env))))
(if goto
(if (< limit (:fuel (env (Neighbors goto))))
{:cmd command :dir goto}
{:cmd :rest}
)
{:cmd :rest}
)
)
)
(defn attack-if-reach-else-advance
[target-selector]
(fn [energy health species env data]
(def hs (hostiles species Neighbors env)) ;; hostile neighbors
(if (empty? hs)
(if (empty? (empty-neighbors env))
{:cmd :rest}
{:cmd :move :dir (last (sections-by-hostiles (empty-neighbors env) env species))}
)
{:cmd :hit :dir (Neighbor-To-Dir (target-selector hs species env))}
)
)
)
(defn most-energy-target-selector-local
"picks a target with the highest amount of energy stored"
[hs species env]
(last (sort-by #(:energy (:occupant (env %))) hs))
)
(defn border-by-diff-atleast-sum-atmost
[leastdiff mostsum]
(fn [energy health species env data]
(def sects (sections-by-friendlies [0 1 2 3 4 5 6 7] env species))
(def counts (vec (map #(count (friendlies species (Env-Sections %) env)) sects)))
(def sum1 (+ (counts 0) (counts 1) (counts 2) (counts 3)))
(def sum2 (+ (counts 4) (counts 5) (counts 6) (counts 7)))
(def diff (- sum2 sum1))
(and (<= leastdiff diff) (>= mostsum sum1)) ; top 4 populated regions at least 5 more frendlies than bot 4. At most 10 in least populated
)
)
(defn divide-if-few-else-move ;For border
[limit divide-behaviour move-behaviour]
(fn [energy health species env data]
(if (> limit (count (friendlies species Environment env)))
(divide-behaviour energy health species env data)
(move-behaviour energy health species env data)
)
)
)
(defn move-to-new-ground
[energy health species env data]
(if (empty? (empty-neighbors env))
{:cmd :rest}
{:cmd :move :dir (first (sections-by-friendlies (empty-neighbors env) env species))}
)
)
(defn move-to-new-ground-if-diff-greater-than
[difflim]
(fn
[energy health species env data]
(def section-order (sections-by-friendlies (empty-neighbors env) env species))
(def sum1 (count (friendlies species (Env-Sections (first section-order)) env)))
(def sum2 (count (friendlies species (Env-Sections (last section-order)) env)))
(def diff (- sum1 sum2))
(if (empty? (empty-neighbors env))
{:cmd :rest}
(if (> diff difflim)
{:cmd :move :dir (first (sections-by-friendlies (empty-neighbors env) env species))}
{:cmd :rest}
)
)
)
)
(defn divide-if-few-else-fuel
[limit divide-behaviour fuel-behaviour]
(fn [energy health species env data]
(if (> limit (count (friendlies species Environment env)))
(divide-behaviour energy health species env data)
(fuel-behaviour energy health species env data)
)
)
)
(defn fuel-if-need-energy-else-move
[fuel-targeter move-behaviour energy-target]
(fn [energy health species env data]
(if (< energy-target energy)
(move-behaviour energy health species env data) ;have enough energy
(if (< 9 (:fuel (env 0 0)))
{:cmd :rest}
(fuel-targeter energy health species env data :move)
)
)
)
)
(def mysoldier (soldier-divide-attack 15 (divide-and-fuel 30 goto-highest-fuel) (attack-if-reach-else-advance most-energy-target-selector-local)))
(def myborder (divide-if-few-else-move 5 (divide-and-fuel 30 goto-highest-fuel) move-to-new-ground))
(def mymiddle (divide-if-few-else-fuel 20 (divide-and-fuel 30 goto-highest-fuel) (fuel-if-need-energy-else-move goto-highest-fuel move-to-new-ground 80)))
(def mymiddle2 (divide-if-few-else-fuel 20 (divide-and-fuel 50 (goto-highest-fuel-if-greater-than 25)) (fuel-if-need-energy-else-move (goto-highest-fuel-if-greater-than 50) (move-to-new-ground-if-diff-greater-than 3) 80)))
;(def Evam-bad (core soldier-if-enemies-nearby mysoldier (border-by-diff-atleast-sum-atmost 5 30) myborder mymiddle))
(def Evam (core soldier-if-enemies-nearby mysoldier (border-by-diff-atleast-sum-atmost 5 30) myborder mymiddle2))
; (def T (tournament
; {
; :red Evam
; :blue Evam2
; ;:yellow (erik_bot 15 0.2 10)
; ;:gray (bot1 weakest-target-selector3)
; :white (create-slightlybrainy 10 70 most-energy-and-fuel-target-selector)
; :orange (create-mutating-slightlybrainy 10 70 most-energy-target-selector-local 0.3 2)
; })
; )
(ns amoebas.competition2019.Necrosis.core
(:use amoebas.defs amoebas.lib amoebas.run)
)
(defn most-energy-and-fuel-target-selector
"picks a target with the highest sum of stored energy and energy in the cell it is in"
[hs species env]
(let
[energy-and-fuel
(fn [cell]
(if (:occupant cell)
(+ (:fuel cell) (:energy (:occupant cell)))
(:fuel cell)
)
)
]
(last (sort-by #(energy-and-fuel (env %)) hs))
)
)
(def Dir-to-Neighbor1 ;; maps direction to the corresponding neighbor we need to move to/hit in/divide into
;; it's the inverse map of Neighbors above
{ 0 [-1 -1] 1 [0 -1] 2 [1 -1] 3 [1 0] 4 [1 1] 5 [0 1] 6 [-1 1] 7 [-1 0] }
)
(defn create-necrosis
[low-energy divide-energy select-target]
(fn [energy health species env data]
(let
[
do-hit2 (fn []
(let
[hs (hostiles species Neighbors env)] ;; hostile neighbors
;; eat
{:cmd :hit :dir (Neighbor-To-Dir (select-target hs species env))} ;; KAPOW!
)
)
do-move (fn []
(let ;; otherwise we gotta move...
[
empty-nb (empty-neighbors env) ;; these are the empty neighbors
by-fuel (sections-by-fuel empty-nb env) ;; this sorts them by the amount of fuel in the corresponding sections
]
(if (empty? empty-nb) ;; no empty neighbors?
(if (empty? (hostiles species Neighbors env))
{:cmd :rest} ;; hunker down, we can't move --- FIXME: perhaps we should hit someone?
(do-hit2)
)
(if (< (:fuel (env (Dir-to-Neighbor1 (last by-fuel)))) (:fuel (env Here)))
{:cmd :rest}
{:cmd :move :dir (last by-fuel)} ;; move toward the most fuel
)
)
)
)
do-fuel (fn []
(if (< MaxFuelingEnergy (:fuel (env Here))) ;; are we *at* a McDonald's?
{:cmd :rest} ;; chomp chomp
(do-move) ;; otherwise, keep looking
)
)
do-hit (fn []
(let
[hs (hostiles species Neighbors env)] ;; hostile neighbors
(if (empty? hs) ;; nobody to hit?
(do-fuel) ;; eat
{:cmd :hit :dir (Neighbor-To-Dir (select-target hs species env))} ;; KAPOW!
)
)
)
do-div (fn [empty-nb]
(def diag [0 2 4 6])
(def intersect (apply clojure.set/intersection
(map set[empty-nb diag])))
(if (not (empty? intersect))
{:cmd :divide :dir (rand-nth (vec intersect))}
{:cmd :divide :dir (rand-nth empty-nb)}) ;; amoeba parenting: drop the child wherever...
)
]
(cond
(< energy low-energy) ;; need some chow?
(do-fuel)
(< divide-energy energy) ;; parenthood!
(let
[empty-nb (empty-neighbors env)]
(if (empty? empty-nb) ;; nowhere to put that crib?
(do-hit) ;; then screw parenthood, hit someone
(do-div empty-nb) ;; oooh, look, it's... an amoeba :-(
)
)
(hostiles species Neighbors env) ;; someone looking at us funny?
(do-hit) ;; whack 'em
:else
(do-fuel) ;; let's eat some more
)
)
)
)
(def Evam (create-necrosis 10 30 most-energy-and-fuel-target-selector))
(ns amoebas.competition2019.tournament
(:use
amoebas.defs amoebas.simulation amoebas.display amoebas.util amoebas.run amoebas.examples clojure.set
)
(:require
amoebas.competition2019.Amoeboiz.core amoebas.competition2019.Necrosis.core
)
)
(def SpeciesColors {
:amoeboiz [255 0 0]
:necrosis [0 0 255]
}
)
(def T (tournament
{
:amoeboiz amoebas.competition2019.Amoeboiz.core/Evam
:necrosis amoebas.competition2019.Necrosis.core/Evam
}
SpeciesColors)
)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment