Group 7: Project 1

Project 1: Rectangles Revisited



Group 7:

Contents:


Introduction


In our approach to the Rectangles Project, we attempted to make a player that would be adaptive, and perform above-average in all cases, from multi-player to 2-on-2, from dense boards to sparse ones. Our final strategy culminated in a player that switched strategies depending on a few key criteria: the number of players, the score of the game, and the number of rounds elapsed. The final player evolved out the players we wrote along the way. By combining those that worked best, such as the Pure Chaser in two-player games and the Army in high-density (many robots) boards, we were able to successfully perform above average in most all of the tournament games.

[ top ]


Diagonal Block Builder


Please note that in all images following, Group 7's player is the orange colored player.
Initial Robot Placement

Our initial strategy began by lining up the robots in a diagonal fashion from the Northwest part of the board down to the Southeast portion. The robots were split up into teams of four. The first two robots were placed in the Northwest corner, one on top of the other. The next two are placed directly East and South of the two players, forming a sideways L-like shape.

Additional robots were placed in the same kind of formation, but 1/5 of the board size to the Southeast. This initial placing algorithm did not account for the placement of more than 24 robots.

Game Strategy:

Once the robots were placed diagonally down the board, and the game begins, the two robots in the NW corner of a given robot team would head in perpendicular directions: one moving South and one heading East. The Robot placed to the South and East of the paired robots would head South and East, respectively. The robots will move the number of spaces that make up 1/5 of the board size. So the four robots together, unobstructed, will form the North and West faces of a rectangle that is 2/5 of the board size.

Once all the robots have moved 1/5 of the board size, they will all switch directions. Those moving East will now move South, and those moving South will now move East.

Once the robots have yet again moved over 1/5 of the board in size, and assuming the borders are still unobstructed, each team of four will have completed a rectangle. In the example to the right, there are 10 robots on the board, and together the two teams of four plus one team of two have formed two rectangles, each 2/5 of the board size in height and width.
They now begin to repeat the process, making a 90 degree turn and heading out once more. The robots continue moving diagonally towards the Southeast corner until the first "rebound." The rebound occurs when a player hits the wall. Upon rebounding, the player first heads one block back the way they came: if they were moving South when they hit the wall, they head back North one square. Once they head back one square, the turn 90 degrees towards the wall. So a robot heading North would turn to face West, and a robot heading West would turn and face North. This causes the formation of new rectangles that run side-by-side with the intial diagonal formed.
Conclusions:

This player does quite well in 2 and 3 player games for fairly large board sizes.Since this player operates along the left diagonal of the board a fair amount of empty board along the lower right-hand corner goes unclaimed. However it does claim significant rectangles in the centre of the board. When pitted against our Grid Player, this player came in a close second.

However it does not do very well in a multi-player (greater than 3) game. One observation is that since these robots are more/less near the centre of the board (where the density is high), the number of collisions with opponents increases, thereby decreasing the score.

[ top ]


Diagonal Block Builder with Chasing


The next player we designed is identical in placement and strategy to the Diagonal Block Builder Player with the exception that it contains a new end game strategy: chasing. After hearing Eric Li's suggestion in class discussion that the chaser player would be optimal in a two player scenario, we decided to try chasing. Chasing is started by an individual robot (or, in the first case, by all robots) after any of the following three conditions were met:

  1. our robots had performed 2 * rebound time rounds.
  2. We defined "rebound time" to mean the number of rounds it took for the first one (or more) of our robots to hit the Southeast corner. For example, if it took 30 rounds for the first robot to reach the opposite wall, we would wait for 60 rounds before beginning to chase.
  3. If one or more squares in the robot's intended path is filled.
  4. In this case, the 1+ black squares would prevent the robot from completing its intended rectangle, so there is no sense in trying to attempt it. Thus, to avoid wasting moves, the robot begins to chase.
  5. If an opponent player touches a Group 7 robot.
  6. Because we are already right next to our opponent if they hit us, it is a perfect time to start chasing as there are no wasted steps trying to reach them.
The chasing algorithm we used for this robot is the same as in the Pure Chaser.

[ top ]


Pure Chaser


Initial Robot Placement:

The robots were initially placed in tight circles around the center of the board, that sprialed out from the middle as there were more robots to place, essentitally creating a number of rings around the middle of the board. The final four robots were placed around the borders. However, in class on September 16th, Professor Kar pointed out that the placement strategy would benefit from some randomness, as it would be easy for other groups to hard code a placement strategy that placed their robots around the border to avoid our chasers from the beginning. So we modified our player to be half random, and half center placement. The robots were placed around the center of the board if their index was even, and randomly if it was odd.
Game Strategy:

This player does pure chasing. It does this irrespective of the number of players and robots being played against (the number of players must be two or more). For a 2-player game, the robots chase the nearest robot of the opponent. For games where (number of players > 2), the robots chase the nearest robot of any opponent. A one-to-one mapping between the chaser and the robot being chased is assumed, i.e. no more than 1 robot of the chaser chases any opponent robot.

Conclusions:

Chasing is a defensive strategy, in the sense that there is no attempt made by the chaser robots to create rectangles on their own.Opponent robots usually adopt the practice of stopping when they detect that they are being chased. A marginal improvement is seen in multi-player games. This is because robots of different teams are being chased and usually there exists a player who does not detect chasing. However this assumption may be flawed.When all opponent robots detect chasing the game come to a standstill and the player fares very poorly. Needless to say, in games where the opponent does not detect chasing , this player performs very well.

Algorithm: We build an array of our robots + the opponent's. we run the nearest neighbor alogorithmto determine the closest opponent robot to each of our robots. we build an array containing this information.

[ top ]


Grid Building Chaser


Initial Robot Placement:

This Player positions its robots along the edges/sides with equal spacings between them. The positioning is dependent on the number of robots. For a fairly small number of robots, the positioning is done on 2 consecutive sides of the board. For a larger number the positioning is done on all sides of the board. The goal is to achieve maximum coverage of the board.

Game Strategy:

The robots move across the board perpendicular to and intersecting each others path. This movement creates a number of small consecutive grids that get colored black. This movement is essentially equivalent to the predominant movement in last year's Grid strategy. The consecutive nature of the grids leads to a higher chance of small grids coalescing to form bigger rectangles, thereby increasing the score. After a certain configurable number of rounds the player stops the grid approach and changes to a chasing mode. The ides behind this approach is that the grid approach in the start-game is to maximise the score , while the chasing approach towards the end helps to consolidate the lead obtained in the game. In case an opponent robot brushes against the grid robot, the latter abandons the grid approach and begins chasing the opponent. The result is that there are fewer robots working offensively to make the grid. The probability of such collisions occuring are higher in a multi-player game than a 2 player one. This Player therefore performs best in a 2-player game.

Conclusions:

This player performs well in 2 and 3 player games. In a multi-player (4 or more) game, the high concentration of opponent robots reduces the number of grids created. Instead the robots switch into chasing mode more often.


An example of the reduction of rectangles created in a 3 player
game versus the 2 player game above.

[ top ]


The Forward Looking Army Player


This player used last year's Group3Player300's strategy2, better known as the army algorithm, as its base.

During class on September 16th, it was made clear that our player did poorly in mulitplayer (>2) sitauations; in order to attempt to make the player more adaptable, and to improve its performance in multi player situations, we began to modify the army of robots algorithm. Taking the code from Group3Player300 of last year, we modified their alogrithm for the army of robots as follows:

In 1-4 player games, this is a pure chaser.

    As a chaser, the placement is either
  1. purely random (for very dense boards -- i.e. the num of robots is > 2*size of board)
  2. semi-random:
    Here, the robots are placed around the center of the board if they are even, and randomly if they are odd.

Because more than half of the squares in the army's intended path are black, it begins to move south rather than charging forward. The green line indicates the path of movement.

In 5+ player games, this player is a modification of the army player. It sweeps across the board, continuing to move East or West as long as the row directly next to it is at least half free (able to be filled). If the row next to it is more than half black, it checks ALL of the squares in its path -- if more than HALF of them are filled, it will go North or South and try a new sweep. Here is a full size screenshot of the army player switching direction.

Conclusions:

This strategy works well when there are a high number of players and greater than two robots. The forward-looking sweep saves time and keeps the player looking for available points, and the fall-back to pure sweeping after 50% of the board is filled ensures the player will pick up any remaining little pieces in the end game. However, in the case where there are only two robots, the army strategy is ineffective because black sqaures can only be formed on a subsequent sweep, assuming the first sweep of color still exists. The second sweep will form rectangles of size four if it can join them, thus gaining only two black squares per move along the second sweep. It would have been better to come up with an alternate strategy for 4+ players but less than three robots.

[ top ]


The Uber Player


2-3 Players Strategy


Initial Robot Placement:

Stage One: Grid

This stage is identical to the strategy in the Grid Player.

Stage Two: Chaser (aka Follow the Leader)

The second stage consists of chasing the player with the highest score. The player begins chasing once:

  1. An individual robot is hit by an opponent robot
  2. In this case, only the robot that was hit starts chasing
  3. 2*board size rounds elapse
  4. If one or more squares in the robot's intended path is filled.
  5. In this case, the 1+ black squares would prevent the robot from completing its intended rectangle, so there is no sense in trying to attempt it. Thus, to avoid wasting moves, the robot begins to chase.

Our initial strategy was to simply chase the nearest neighbor. then, we further refined it so that if the closest robot(s) had a lower score than our player, that robot is ignored in the selection process. thus, our chaser would only chase those players whose scores are higher than our own. in the event that ours is the highest score, our robot simply chases the nearest neighbor.

We changed this strategy because we noticed that once we chose a single player with a score higher than ours, another player may jump into the lead. so we tried to simply chase the player with the highest score, and this turned out to work better than the above strategies in the tests we ran.

Countering the Counter-Chasers

In the event that the chasee stops in an effort to beat our chaser, one of two things happen:

  • If we are in the lead, we simply stay stopped as long as the chasee is stopped.
  • If we are losing, as long as the chasee is stopped, we move around randomly, in hopes of getting a few extra points. If the chasee's detection of our chasing is not sophisticated, it will begin moving again, and we will resume chasing, and hopefully gain more points in the process.
  • If the score is tied, we simply stop.
The fact that we stop if the score is tied was an oversight on our part that could have easily been fixed by chaging an if condition. This probably would have resulted in a higher ranking in the 2-player, 2-robot tournament scenario. However, this counter-chasing strategy is key to prolonging the game and clinching a win in most cases, because it circumvents the counter-chasing strategy of simply getting lots of points in the beginning and then stopping. Because the player moves around randomly, while still maintaining the chase when the chasee resumes movement, the opponents' score is, in the best case, frozen at the point in which they first stopped all of their robots. This happens because our robot tends to overwrite the opponent's squares, making it less likely that the opponenet forms any additional rectangles. So while we may be far behind in the beginning of the game, as in the example below, we are able to pull ahead, little by little, into a win, simply by using the random movement upon the chasee's stop.

The green players have stopped, so our players begin to move psuedo-randomly, tending more heavily towards either white squares or the opponent's colored sqaures. When the opponent begins moving again, the chase resumes.
These images illustrate an extreme example of our Uber player's 'never say die' attitude, coming back from a score of 575 to 11, to ultimately overcome with a 575-576 score, clenching the win. (Click on any of the below images to enlarge).

[ uber player  top ]

4+ Players Strategy


Initial Robot Placement:

The placement strategy for 4+ players is the same as that in the Forward Looking Army player.

Stage One: Modified Army

The very first move is to stand still. This is to ensure that, in the event another player is using the Army strategy, and lines up their robots in the same place as ours, we will effectively chase them and pick up all their points, rather than be on top of them and nullify both our scores. We chose to implement this after a test run in class on September 18th revealed the overlapping Army players scenario.

After the first STAY move, it sweeps across the board, continuing to move East or West as long as the row directly next to it is at least half free (able to be filled). If the row next to it is more than half black, it checks ALL of the squares in its path -- if more than HALF of them are filled, it will go North or South and try a new sweep.

Stage Two: Army
This is simply the sweeping strategy used by the Group3Player300 of last year. It launches into this strategy once 50% of the board is colored black. We played around with a number of percentages here, ranging from 75%-50%. Though 3/4 of the board filled in black seemed more reasonable at first than .5, doing some trial runs, the board typically has very little white squares left once 50% is shaded black, as the majority of the remaining squares consist of all the covered borders. So we settled on 50% for the final player.

[ uber player  top ]


Tournament Results and Conclusions:


For the two player games, we used a grid-like start player which eventually switched to a pure chaser. The grid-like offense probably contributed greatly to many of our wins. It is likely we were either close or ahead by the time we started chasing. Most other players tried to stop when they realize they are being chased. If we reach the opponent and they have stopped and we are in the lead, then we win the game. If we reach the opponent and they have stopped and we are not in the lead, we move about somewhat randomly in the hopes that we continue to get more points. This works very well for greater than five robots. The two player tournament results show this: 10 Robots, 2 Player2, n = 40 (first place), 10 Robots, 2 Player2, n = 50 (first place), 20 Robots, 2 Players, n = 50 (first place), 3 Robots, 2 Players, n = 50 (second place), 5 Robots, 2 Players, n = 50 (first place), Older player tournament, 10 Robots, 2 Players, n = 30 (first place), 10 Robots, 2 Players, n = 40 (first place). There was only one two-player tournament that we did not come in first place and that one we came in second. Moreover, in the four out of the five tournaments that had 10 or more robots, we did not lose a single match going 257-7-0. The seven ties were due to a programming logic error in which our chasers stop once they are in the lead, which is true even for ties.

In the four and all player tournaments, we used the modified army strategy. First of all, the army waits one turn before moving, making it vurtually impossible to overlap another army player. Second of all, the army tries to avoid marching over high density black areas. And third of all, the army becomes a pure army once the board is mostly black. This strategy was not aimed at winning every match, but was aimed at placing well in every match. This can be shown with the tournament results: 10 Robots, 4 Players, n = 30 (first place), 2 Robots, 4 Players, n = 40 (fifth place), 10 Robots, 6 Players, n = 50 (second place), 20 Robots, 6 Players, n = 50 (first place), 3 Robots, 6 Players, n = 50 (third place), 2 Robots, 6 Players, n = 50 (third place), 5 Robots, 6 Players, n = 50 (third place). The tournaments the we did poorly with the army strategy were the ones with a small number of robots.

Overall, we feel our player performed admirably in all tournaments. We did not always win, but we never placed worse than fifth. We accomplished our goal of creating an adaptable player that performed above average in most scenarios. Two improvements to our player might be fixing the chaser stopping when there is a tie, and changing the army strategy when the number of robots is very small.