Skip to content

Commit

Permalink
support 'equal to the number of objects destroyed this turn' (fix #228
Browse files Browse the repository at this point in the history
…- at least the best way possible for now)
  • Loading branch information
AlexNisnevich committed Feb 12, 2025
1 parent 234e2a2 commit c37593d
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/main/scala/wordbots/CodeGenerator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ object CodeGenerator {
case Half(num, RoundedDown) => s"(Math.floor(${g(num)} / 2))"
case Half(num, RoundedUp) => s"(Math.ceil(${g(num)} / 2))"
case MaximumEnergyAmount(player) => s"maximumEnergyAmount(${g(player)})"
case NumberOfObjectsDestroyedThisTurn => s"numberOfObjectsDestroyedThisTurn()"
case ThatMuch => "thatMuch()"
case Times(n1, n2) => s"((${g(n1)}) * (${g(n2)}))"

Expand Down
1 change: 1 addition & 0 deletions src/main/scala/wordbots/Lexicon.scala
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,7 @@ object Lexicon {
(PP/PP, λ {c: GlobalCondition => NotGC(c)})
)) +
("number" -> (Num/PP, λ {c: Collection => Count(c)})) +
("number of objects destroyed this turn" -> (NP, NumberOfObjectsDestroyedThisTurn: Sem)) +
(("object".s :+ "objects '") -> (N, AllObjects: Sem)) +
("odd" -> (NP/N, λ {attr: Attribute => AttributeComparison(attr, IsOdd)})) +
("of" -> Seq(
Expand Down
1 change: 1 addition & 0 deletions src/main/scala/wordbots/Semantics.scala
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ object Semantics {
case class EnergyAmount(player: TargetPlayer) extends Number
case class Half(num: Number, rounding: Rounding) extends Number
case class MaximumEnergyAmount(player: TargetPlayer) extends Number
case object NumberOfObjectsDestroyedThisTurn extends Number
case object ThatMuch extends Number // salient amount
case class Times(num1: Number, num2: Number) extends Number

Expand Down
1 change: 0 additions & 1 deletion src/main/scala/wordbots/Server.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import org.http4s.server.blaze.BlazeBuilder
import io.circe._
import io.circe.generic.auto._
import io.circe.syntax._
import org.log4s.MDC.result
import scalaz.Memo
import scalaz.concurrent.Task
import wordbots.Semantics.AstNode
Expand Down
11 changes: 6 additions & 5 deletions src/test/scala/wordbots/ParserSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -307,12 +307,13 @@ class ParserSpec extends FlatSpec with Matchers {
parse("Give 1 health to all robots you control") shouldEqual parse("Give all robots you control 1 health")
parse("All friendly robots lose 1 speed and 1 health and 1 attack") shouldEqual
MultipleActions(Seq(
SaveTarget(ObjectsMatchingConditions(Robot,List(ControlledBy(Self)))),
ModifyAttribute(SavedTargetObject,Speed,Minus(Scalar(1))),
ModifyAttribute(SavedTargetObject,Health,Minus(Scalar(1))),
ModifyAttribute(SavedTargetObject,Attack,Minus(Scalar(1)))
SaveTarget(ObjectsMatchingConditions(Robot, List(ControlledBy(Self)))),
ModifyAttribute(SavedTargetObject, Speed, Minus(Scalar(1))),
ModifyAttribute(SavedTargetObject, Health, Minus(Scalar(1))),
ModifyAttribute(SavedTargetObject, Attack, Minus(Scalar(1)))
))
parse("Choose a tile") shouldEqual SaveTarget(ChooseT(AllTiles,Scalar(1)))
parse("Choose a tile") shouldEqual SaveTarget(ChooseT(AllTiles, Scalar(1)))
parse("Lose life equal to the number of objects destroyed this turn") shouldEqual DealDamage(Self, NumberOfObjectsDestroyedThisTurn)
}

it should "treat 'with' as 'that has'" in {
Expand Down

0 comments on commit c37593d

Please sign in to comment.