Skip to content

Commit

Permalink
[game] resolve head to head collisions
Browse files Browse the repository at this point in the history
  • Loading branch information
ghthor committed Feb 21, 2015
1 parent 6f06b15 commit b38ff76
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
3 changes: 3 additions & 0 deletions game/sim.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ func (phase narrowPhase) resolveActorActorCollision(a, b *actor) {
a.undoLastMoveAction()
b.undoLastMoveAction()

case coord.CT_HEAD_TO_HEAD:
fallthrough

case coord.CT_FROM_SIDE:
if a.pathAction.Start() < b.pathAction.Start() {
// A has already won the destination
Expand Down
58 changes: 58 additions & 0 deletions game/sim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,64 @@ func DescribeCollision(c gospec.Context) {
})
}
})

c.Specify("head to head", func() {
testCases := []spec_2moving{{
spec: "moving south loses to moving north",
paths: []coord.PathAction{
pa(0, 10, cell(0, 0), cell(0, 1)),
pa(0, 10, cell(0, 2), cell(0, 1)),
},
expectations: func(testCase spec_2moving, index actorIndex, c gospec.Context) {
c.Assume(testCase.paths[0].Direction(), Equals, coord.North)
c.Assume(testCase.paths[1].Direction(), Equals, coord.South)
c.Expect(*index[0].pathAction, Equals, testCase.paths[0])
c.Expect(index[1].pathAction, IsNil)
},
}, {
spec: "moving west loses to moving east",
paths: []coord.PathAction{
pa(0, 10, cell(0, 0), cell(1, 0)),
pa(0, 10, cell(2, 0), cell(1, 0)),
},
expectations: func(testCase spec_2moving, index actorIndex, c gospec.Context) {
c.Assume(testCase.paths[0].Direction(), Equals, coord.East)
c.Assume(testCase.paths[1].Direction(), Equals, coord.West)
c.Expect(*index[0].pathAction, Equals, testCase.paths[0])
c.Expect(index[1].pathAction, IsNil)
},
}, {
spec: "moving slower loses to moving faster",
paths: []coord.PathAction{
pa(0, 9, cell(0, 0), cell(-1, 0)),
pa(0, 10, cell(-2, 0), cell(-1, 0)),
},
expectations: func(testCase spec_2moving, index actorIndex, c gospec.Context) {
c.Assume(testCase.paths[0].Direction(), Equals, coord.West)
c.Assume(testCase.paths[1].Direction(), Equals, coord.East)
c.Expect(*index[0].pathAction, Equals, testCase.paths[0])
c.Expect(index[1].pathAction, IsNil)
},
}, {
spec: "moving first wins",
paths: []coord.PathAction{
pa(0, 10, cell(0, 0), cell(-1, 0)),
pa(1, 9, cell(-2, 0), cell(-1, 0)),
},
expectations: func(testCase spec_2moving, index actorIndex, c gospec.Context) {
c.Assume(testCase.paths[0].Direction(), Equals, coord.West)
c.Assume(testCase.paths[1].Direction(), Equals, coord.East)
c.Expect(*index[0].pathAction, Equals, testCase.paths[0])
c.Expect(index[1].pathAction, IsNil)
},
}}

for _, testCase := range testCases {
c.Specify(testCase.spec, func() {
testCase.runSpec(c)
})
}
})
})
})

Expand Down

0 comments on commit b38ff76

Please sign in to comment.