My AI has been though some massive changes. The original idea for my AI was to have different groups of units to perform specific actions. The behaviors were attack, defend and wander.
After trying to get my AI to work with little success. I rethought my whole approach. In the game the player gets points from owning cities and having units created. In the game units can't be on the same tile, unless the tile is a city. Using all this knowledge I devised a new algorithm to play Empire. My new strategy is to sit in the city and keep making armies as fast as possible. Armies are the quickest unit to make, so I will get more points for only making them. Armies will only venture out from the city to attack enemies units next to the city.
The day of the competition, my algorithm was disappointing in the competition. There were bugs in my code during the competition. In the first game I lost because my first unit moved to a water tile. When I tested the AI, the army unit would move to a land tile. This broke my strategy because the storms at sea wiped out my units. Then I lost in the first round of the loser's bracket because my AI isn't fast enough to win in a match with 3 people. It thrives on 4 people trying to take out each other.
Showing posts with label Artificial Opponents. Show all posts
Showing posts with label Artificial Opponents. Show all posts
Friday, December 16, 2016
Friday, December 2, 2016
Empire Planning Post 2
This second part of Empire takes into account the battle element. In the first part it was about single player exploration. Now its about multi player battling and conquering cities. There are three parts of the AI for battling. The three are scouting, defending, and attacking.
I am gonna modify the exploration AI to not travel over water. One storm on the sea could wreck my whole army. This happened in the exploration competition. So I am still gonna use similar code, where the army units will move to the closest hidden tile. Although if the unit is on a water tile, it will move to get out of the water tiles.
The second part, defend, is about defending the city so that other players won't conquer my cities. This AI is pretty basic. The AI will just circle around the city. This way if an enemy is trying to conquer my cities, my defending units will try to kill the attackers.
The third part is attacking either other cities or enemies. These units will group outside the city, on land. This way the units won't get destroyed by the storm on the seas. Then when there is a revealed city that my AI doesn't own, the attackers will travel to the city and try to take it over.
When my AI combines these three techniques. The AI should be pretty decent at Empire.
I am gonna modify the exploration AI to not travel over water. One storm on the sea could wreck my whole army. This happened in the exploration competition. So I am still gonna use similar code, where the army units will move to the closest hidden tile. Although if the unit is on a water tile, it will move to get out of the water tiles.
The second part, defend, is about defending the city so that other players won't conquer my cities. This AI is pretty basic. The AI will just circle around the city. This way if an enemy is trying to conquer my cities, my defending units will try to kill the attackers.
The third part is attacking either other cities or enemies. These units will group outside the city, on land. This way the units won't get destroyed by the storm on the seas. Then when there is a revealed city that my AI doesn't own, the attackers will travel to the city and try to take it over.
When my AI combines these three techniques. The AI should be pretty decent at Empire.
Labels:
Artificial Opponents,
Empire
Monday, November 7, 2016
Empire Planning Post
This assignment is to make an AI to play Empire, a real time strategy game. There are two major parts to this AI, exploring and combat. The first part of the assignment is exploring. The AI will get a points for exploring hidden tiles, it only has a limited number of turns to get the highest score.
In exploring there are two decisions that need to be made, what unit should be made and what direction should a unit travel. Since in this version of Empire, army units can travel on land and water. My AI will just make armies. There is a 5% chance that units on the water could take damage. Since armies only have 1 health, they would be killed. I find this small chance negligible though, since the AI will be as efficient as possible only making armies.
The way that I was thinking of implementing my movement was a modified dijkstra algorithm. A unit will find the magnitude of every hidden tile. Then it will move to the closest hidden tile. If there is an unoccupied city near a unit, that unit will capture the city. This way more army units can be made, and more tiles can be revealed.
While using these methods, adding in a combat portion will be easy. I would just have to change it so the units would move to an enemy if it is close enough and attack.
In exploring there are two decisions that need to be made, what unit should be made and what direction should a unit travel. Since in this version of Empire, army units can travel on land and water. My AI will just make armies. There is a 5% chance that units on the water could take damage. Since armies only have 1 health, they would be killed. I find this small chance negligible though, since the AI will be as efficient as possible only making armies.
The way that I was thinking of implementing my movement was a modified dijkstra algorithm. A unit will find the magnitude of every hidden tile. Then it will move to the closest hidden tile. If there is an unoccupied city near a unit, that unit will capture the city. This way more army units can be made, and more tiles can be revealed.
While using these methods, adding in a combat portion will be easy. I would just have to change it so the units would move to an enemy if it is close enough and attack.
Labels:
Artificial Opponents,
Empire
Friday, October 21, 2016
Gin Rummy Postmortem Analysis Post
The Gin Rummy tournament happened on 10/21/16. I wanted to win the whole tournament, but I only thought my AI would get to the final four. I took
second place in the competition. Second place is good but I only lost
by 3 points, so my AI and my opponent's AI were very close in skill.
The day of the tournament I had high hope that my AI would be a contender. I was right because the first match, my AI shutout the opponent. I kinda feel bad for that, but I made my AI to be as best as possible.
I think the only way I could have tried to improve my AI is to improve what card it discards. It first checks a vector is to see if there are any useless cards in my hand. This would include a 6 of clubs, if it had nothing that can use that card. Then it checks to see if it has any cards in the discarded vector. This would include if it had a two pair and the other cards are in the discard pile. It can't use them so it will discard them. If both those vectors are empty. It starts to discard the highest valued card form the incomplete run vector. Then the highest value card of the two pair vector. So maybe if the AI picked the highest value card that was in a combined incomplete run/two pair vector. This way my hand would always try to have the lowest score. Although it might just mess up my algorithm and loss more often.
The day of the tournament I had high hope that my AI would be a contender. I was right because the first match, my AI shutout the opponent. I kinda feel bad for that, but I made my AI to be as best as possible.
I think the only way I could have tried to improve my AI is to improve what card it discards. It first checks a vector is to see if there are any useless cards in my hand. This would include a 6 of clubs, if it had nothing that can use that card. Then it checks to see if it has any cards in the discarded vector. This would include if it had a two pair and the other cards are in the discard pile. It can't use them so it will discard them. If both those vectors are empty. It starts to discard the highest valued card form the incomplete run vector. Then the highest value card of the two pair vector. So maybe if the AI picked the highest value card that was in a combined incomplete run/two pair vector. This way my hand would always try to have the lowest score. Although it might just mess up my algorithm and loss more often.
Monday, October 10, 2016
Gin Rummy Code Report
When making a Gin Rummy AI, there are two ways to go, make it simple or make it complex. I chose the latter. There are really only two choices to make, what pile to pick up from and what card to discard. It is hard to test to see how good the AI actually runs because the default AI just throws out the highest value card. Although my AI did beat it.
The AI algorithm I used was very similar to the one I mentioned in the planning post. The first decision that the AI has to make is what pile to pick up from. Using the knowledge of the top card in the discard pile. It can make the intended choice. In my algorithm my AI will only pick up from the discard pile. If the card will complete or continue a completed run/set. This way if the opponent is trying to use probability on my hard. It would be useless. It is also better to pick from the deck instead of the discard pile. It could give you and your opponent potentially more helpful cards. These cards are unknown unlike all the known cards of the discard pile
The second decision my AI has to make is what card to discard. It am utilizing a vector to keep track of all the cards in the discard pile. This way it can make logical decisions. It won't try to keep two kings if the other two are in the discard pile. This vector is the most important part of my discard algorithm.
When it calls the function to decide a card to discard. It removes all the completed sets/runs first. Then it checks to see if it has two cards of a set. If it has two cards it checks to make sure the other needed cards aren't in the discard pile. If they are, it adds the cards to the potential discard vector. If they aren't in the discard pile. It adds the cards to the two card set vector. When it is finished going through all the cards in the hand, excluding completed runs/sets, it removes the two card set vector from its hand. It then go through the same process looking for runs. It is a little bit different because the AI has to see if the card it is missing is in the front, middle or end. Once it runs through all of the cards in the hand,excluding completed runs/sets, it removes the valid two card runs from its hand.
Then it picks the card with the highest point value from the remaining cards. If there is no remaining cards left in the hand after removing the completed run/sets and the almost completed run/sets. Then it picks the highest value from the potential discard vector. If that vector has zero elements. Then it checks the two cards run/sets vectors. If those fail, the AI probably has gin rummy but my AI knocks as soon as the total hand score is less than 10.
The AI algorithm I used was very similar to the one I mentioned in the planning post. The first decision that the AI has to make is what pile to pick up from. Using the knowledge of the top card in the discard pile. It can make the intended choice. In my algorithm my AI will only pick up from the discard pile. If the card will complete or continue a completed run/set. This way if the opponent is trying to use probability on my hard. It would be useless. It is also better to pick from the deck instead of the discard pile. It could give you and your opponent potentially more helpful cards. These cards are unknown unlike all the known cards of the discard pile
The second decision my AI has to make is what card to discard. It am utilizing a vector to keep track of all the cards in the discard pile. This way it can make logical decisions. It won't try to keep two kings if the other two are in the discard pile. This vector is the most important part of my discard algorithm.
When it calls the function to decide a card to discard. It removes all the completed sets/runs first. Then it checks to see if it has two cards of a set. If it has two cards it checks to make sure the other needed cards aren't in the discard pile. If they are, it adds the cards to the potential discard vector. If they aren't in the discard pile. It adds the cards to the two card set vector. When it is finished going through all the cards in the hand, excluding completed runs/sets, it removes the two card set vector from its hand. It then go through the same process looking for runs. It is a little bit different because the AI has to see if the card it is missing is in the front, middle or end. Once it runs through all of the cards in the hand,excluding completed runs/sets, it removes the valid two card runs from its hand.
Then it picks the card with the highest point value from the remaining cards. If there is no remaining cards left in the hand after removing the completed run/sets and the almost completed run/sets. Then it picks the highest value from the potential discard vector. If that vector has zero elements. Then it checks the two cards run/sets vectors. If those fail, the AI probably has gin rummy but my AI knocks as soon as the total hand score is less than 10.
Sunday, September 25, 2016
Gin Rummy Planning Post
For this assignment we have to make an AI to play gin rummy. Since I have never played gin rummy, I had to look at tutorials. I have however played rummy and rummy 500 before so I knew the basics of these types of card games.
The AI will use a vector to keep track of all the cards in the discard pile. It will mostly pick up from the deck, it will only pick up from the discard if that card completes a run/set or adds to a completed run/set. In gin rummy games, picking up from the discard pile is not advised because it tells the other player more cards in your hand. So instead of having ten unknown cards you only have nine. Using this knowledge, your opponent can make educated guesses on what cards you are looking for or what cards you hold and alter the cards that he or she will discard. Since I don't know if other peoples AIs will using this knowledge to their benefit. My AI will only be picking up cards that are guarantee to help.
Since my AI is keeping track of the discard pile it can make educated decisions with what card to discard. Since a game of gin rummy can end at any time, it would be wise to keep the lowest score in your hand at all times. So it will discard the highest valued, useless card. An example would be my hand is [King of hearts, King of diamonds, Jack of spades, 10 of diamonds, 5 of hearts, 4 of spades, 4 of hearts, 2 of spades, 2 of clubs, 2 of diamonds]. Providing that there is no kings in the discard pile, my highest values useless card is the jack, then the 10. If the discard piles has 6 of hearts and a 3 of hearts it will discard the 5 of hearts if it is the highest useless card. Then if the total number of deadwood in my hand is less than 10, the AI will knock ending the game.
The AI will use a vector to keep track of all the cards in the discard pile. It will mostly pick up from the deck, it will only pick up from the discard if that card completes a run/set or adds to a completed run/set. In gin rummy games, picking up from the discard pile is not advised because it tells the other player more cards in your hand. So instead of having ten unknown cards you only have nine. Using this knowledge, your opponent can make educated guesses on what cards you are looking for or what cards you hold and alter the cards that he or she will discard. Since I don't know if other peoples AIs will using this knowledge to their benefit. My AI will only be picking up cards that are guarantee to help.
Since my AI is keeping track of the discard pile it can make educated decisions with what card to discard. Since a game of gin rummy can end at any time, it would be wise to keep the lowest score in your hand at all times. So it will discard the highest valued, useless card. An example would be my hand is [King of hearts, King of diamonds, Jack of spades, 10 of diamonds, 5 of hearts, 4 of spades, 4 of hearts, 2 of spades, 2 of clubs, 2 of diamonds]. Providing that there is no kings in the discard pile, my highest values useless card is the jack, then the 10. If the discard piles has 6 of hearts and a 3 of hearts it will discard the 5 of hearts if it is the highest useless card. Then if the total number of deadwood in my hand is less than 10, the AI will knock ending the game.
Friday, September 16, 2016
Minesweeper Postmortem Analysis Post
The minesweeper AI competition didn't go
as I expected, my AI underachieved. It was confusing
why it performed so poorly. The AI was checking for probability of
where the mines could be and it was marking tiles that is knew was
mines. So i was confused why it was so bad.
After the class I was talking to a
friend about how my AI should have been better because I am using probability. Then I remembered that I assign a probability to every
hidden tile. The probability is based on how many mines are adjacent
to that tile. Which means if the hidden tile is surrounded by other
hidden tiles, the probability that is will be a mine is low. So when
the AI couldn't guarantee that the tile picked is free. It picked a
random tile with a low probability. Since my probability was calculated
incorrectly, my Algorithm was flawed.
Monday, September 12, 2016
Minesweeper Code Report
I used numerous techniques in my
minesweeper AI, but the one that was utilized the most was one that
marked mines. When a game starts it picks the tile in the middle,
this way the AI will hopefully get a good number of open tiles. After
the first turn the algorithm starts to go through its algorithm.
The algorithm starts at index zero and
runs through all the tiles' indexes. If the index is hidden it is
pushed into a hidden tile vector. Then the algorithm does its first
big check to save time and cpu power. It checks to see if the current
index is revealed and if the number of adjacent mines is bigger than
zero. The AI doesn't care if the tile is hidden or if the number is
zero because it can't do anything about those tiles.
The algorithm checks to see how many
tiles are hidden. If the number of hidden tiles are equal to the
number of adjacent mines, it knows that those tiles are all mines.
The new tiles that are marked as mines are check to see if they are
already in the mine index vector. If they are not in the vector they
are pushed in. Once the mines are marked then it goes through the
adjacent tiles of the index that it is at and see if any of them are
are mines. If one of them isn't a mine then it returns that index.
If the algorithm goes through all that
and it still can't guarantee a index that isn't a mine. It uses the
vector that has all the hidden tiles and deletes all the indexes that
are mines. Then it just picks a random tile.
The algorithm wins between 52-57
percent. If I have more time, I want to implement a feature that uses
a vector to hold possible adjacent and mine-less hidden tiles. Then
when it checks to see if a mine is in one of those tiles. It will
just delete that index. Then if the vector size is greater than zero
after checking all the adjacent hidden tiles, it will just return the
first element. This will hopefully improve the win rate because it
will be utilizing this method to make educated guesses instead of
just random guesses.
Friday, September 2, 2016
Minesweeper Planning Post
The
assignment is to make an artificial opponent that can beat
minesweeper. Since I have never really beaten minesweeper, the first
step is to learn how to play. So I looked up tutorials on how to play
correctly. Then I was playing some games so that I can get the feel
for what the AI will be attempting to accomplish.
The
goal is to make an AI that can beat every game of minesweeper without
taking a long time. The AI will be programmed to play the game just
like a human. It will pick tiles that it knows aren't mines, while
marking tiles it knows are mines. Even though the AI will follow an
algorithm that follows the thought process of a human, it should be
better because it won't make human mistakes.
The
AI will basically be checking a whole bunch of cases to see what tile
to pick. Even thought a computer can run over a billion calculations
a second. I can't have the AI check each case on each tile. It will
not only become a waste of time but it will also be a waste of the
CPU. So the AI will check to see what tile is the best to run the
numerous conditions on. Since minesweeper is a logic game one needs
to have some evidence to pick a non-mine tile. Therefore the first
pass of the algorithm the tiles that have open sides will be
selected. If all the sides are opened or marked as mines, it will
pass that tile. This will hopefully cut back on time and CPU power
making the algorithm faster.
Subscribe to:
Posts (Atom)