Archipelago - Computer Opponents - Avoiding Pirate Ships and Building

in #utopian-io6 years ago (edited)

Introduction

In the last Archipelago contribution I started on a one player version of the game with one human player taking on three computer opponents. The code for the human player was already completed in phases 1-3 of development so the work involved adapting this code for automated moves and in particular coding the decision making process for the computer players.

The first development contribution for the computer opponents focused on resource collection; getting the ships moving and scuttling around the board, investigating undiscovered islands and claiming resource pieces. The next step, covered by this contribution, is to help the computer players avoid the pirate ships that track them down and seek to engage in sea battles.

The decision making process is based around a rating system for each potential move. The approach to the pirate ship avoidance works by reducing the rating for a move that ends in the target area of a pirate ship with the reduction in rating higher the closer the distance to the pirates. A later refinement (in line with the development below) introduced probabilities of capture and a more explicit impact of losing moves to repair.

In the last few days I also worked on enhancing the decision making of resource searching for computer opponents with the development of a points-and-probability based system. The aim is to devise a rating system to allow comparability across all potential moves, whether they be resource searching, goods delivery or taking refuge in harbours, as well as ensuring that the reduction to ratings from pirates is consistently weighted. The first step in this development is now complete.

Finally I developed the shipbuilding decision making for computer opponents. In general it is beneficial to build a new ship as soon as you have the resources available so the main decision here is which ship to build.

In summary the development included in this contribution is:

  • Computer opponents - avoiding pirate ships
  • Computer opponents - improving decision making of resource search
  • Computer opponents - building new ships



Screen Shot 2018-08-18 at 14.22.18.png

For a full view of the current state of the game development see my github-hosted page.
https://miniature-tiger.github.io/archipelago/

Please note that the game is not yet complete - you can see current progress and test functionality but you will have to wait a little longer to play!

Background details of the project can be found at the end of this contribution post.


Repository

The repository for Archipelago can be found here:
https://github.com/miniature-tiger/archipelago


New Features covered by this Contribution

Computer opponents - avoiding pirate ships

Previously computer opponents could search for resource tiles but they did so oblivious to any danger from pirate ships. This features brings the potential impact of pirate ships into the ranking system for moves.

The development reduces the rating for a move that ends in the target area of a pirate ship, with the reduction in rating higher the closer the distance to the pirates. The aim of this approach is to make moves close to pirate ships less attractive but without preventing high scoring moves that would subsequently result in a pirate attack (e.g. a move that completes the resource task and gains 5 points is worthwhile even if it then results in pirate damage).

Initially the pirate cost was just based on the distance to each pirate ship, i.e. a 5 tile distance was a 1 point reduction in rating, ramping up to a 5 point deduction for moves directly next to pirate ships. This approach was refined when the probability-and-points feature (see below) was introduced. Now there is a probability of pirate attack based on distance and a penalty based on the expected number of moves lost.

In the example below the red catamaran chooses to investigate the central island rather than the islands closer to pirate ships.


Screen Shot 2018-08-18 at 11.20.29.png
Screen Shot 2018-08-18 at 11.21.07.png

Red catamaran avoiding pirate ships.

The code changes for the new feature can be found here:
https://github.com/miniature-tiger/archipelago/commit/d5c319a67ea9ef1236888e6484633e2610d36165
The additional refinement is below:
https://github.com/miniature-tiger/archipelago/commit/9eff2e9eb4b28b594d9b761b4e6c952a4d5bddf5

The capture probability and move penalty figures are currently hardcoded for simplicity due to the complexities of (a) having two pirate ships are in the vicinity (b) the need to take into account the distance to the nearest safe harbour. Both of these elements will be refined in future.

Computer opponents - improving decision making of resource search

The previous ranking method for determining which island to investigate for resources was quite simple. This led to some sub-optimal decision making towards the end of the resource search process where computer opponents would continue to search undiscovered islands even if a previously discovered but unclaimed resource was a better option.

A new "points-and-probabilities" method has now been added which combines the probabilities of finding each of the six resources with points ratings to represent the benefit from claiming each resource to give an overall points benefit for each undiscovered island search. This allows a direct comparison between the likely points to be obtained from searching an undiscovered island with the points to be earned from claiming a previously discovered but unclaimed resource (but which may be two or three moves away in distance) allowing better decisions to be made between these two possibilities.

The probabilities take into account the number of each resource left to be discovered. The points allow for the rewards on offer for being the first to discover a resource type as well as cumulative rewards for finding three or all six resource types as well as "game progression" allowances for the usefulness of each type of resource (e.g. extra points for those resources required for building ships).

The overall aim here is to devise a rating system for all potential moves, whether they be resource searching, goods delivery or taking refuge in harbours, as well as ensuring that the reduction to ratings from pirates is consistently weighted.

In the example below the orange catamaran ignores the nearer undiscovered island and heads straight to claiming the ironworks, one of the last resource tiles the player needed at this point in the game.


Screen Shot 2018-08-18 at 11.50.32.png
Screen Shot 2018-08-18 at 11.50.52.png

Orange catamaran making the right choice.

The code changes for the above new feature can be found here:
https://github.com/miniature-tiger/archipelago/commit/2250575fec5085cc8158800d05784f096f3dbfb0

As noted in the first feature above, the pirate avoidance ranking system was also updated for consistency with this new approach.

Computer opponents - building new ships

Shipbuilding is a fairly simple decision-making process since it does not impact any of the current ships on the board so there is no raking required against other possible moves. In general it is beneficial to build a new ship as soon as a player has the resources available so the main decision is which ship to build.

There are different resource requirements for each ship meaning that one ship type may become available before the other. There are also points bonuses in the game for being the first to build a particular ship and these bonuses dictate which ship is chosen if both ships become available at once. Finally there is a forced preference for the warship if the bonus points to be awarded are equal for each ship type, simply because it is a slightly better choice earlier in the game (smaller and faster when contract delivery amounts are lower). There is a potential to code different strategies here and it is likely to be an area of further development once the contract delivery decision making process is implemented.

In the example below the red team is one wood away from the requirements of a cargo ship and one iron short from the requirements of a warship. The player will have the choice at the start of the next move to build either kind of ship. At the next move a warship is chosen due to the higher bonus points available since the green team has already started on a cargo ship.


Screen Shot 2018-08-18 at 14.15.09.png
Screen Shot 2018-08-18 at 14.15.21.png
Screen Shot 2018-08-18 at 14.15.37.png
Screen Shot 2018-08-18 at 14.16.11.png

Red team warship building decision.

The code changes for the above new feature can be found here:
https://github.com/miniature-tiger/archipelago/commit/7759507cf177cf93f9c136793d32f8e7647fbf9d
and here:
https://github.com/miniature-tiger/archipelago/commit/664f33f26983b0d9e3e4cf3dd6a8b57b979330f0


Proof of Work Carried Out

This is the full url to my github account:
https://github.com/miniature-tiger


That is all for this update. If you have any queries please drop them in the comments or contact me on discord.


Details of the Archipelago Project

What is the Project About?

Archipelago is a new project that I have been working on. The aim is to develop a seafaring and trading turn-based strategy game. Players will guide their ships around the islands, searching for goods to aid construction of ships and their bases, trading with the Kingdom settlements and avoiding hazards like pirates and whirlpools.

Technology Stack

The project is a browser based game:

  • Mechanics: Javascript
  • Visuals: HTML and CSS initially but now moved across to Canvas and SVG.

Roadmap

Development phases 1, 2 and 3 are now complete!
Work will now focus on phases 4, 5 and 6.

Phase 1 - Board and ship movement: COMPLETE
Phase 2 - Resources, Goods, Building and Trade Contracts: COMPLETE
Phase 3 - Conflicts: COMPLETE
Phase 4 - One Player Version development

Surround, dashboards, commentary:

  • Keep dashboards fixed on one player with option to switch to other teams
  • Change commentary to focus on single player - with updates on other team moves

Resource tile search phase:

  • Get all ships moving - COMPLETE
  • Automate search for resource tiles - COMPLETE
  • Automate claiming of resource tiles - COMPLETE

Conflicts:

  • Automate avoidance of pirate ships - COMPLETE
  • Automate ship return to nearest harbour after damage taken - COMPLETE

Contracts for delivery:

  • Automate collection of goods
  • Automate delivery of goods

Shipbuilding

  • Automate decision to build ships - COMPLETE
  • Automate teamworking so that ships on same team do not pursue same targets

Strategies and AI for computer players

  • Produce array of ships with game strategies
  • Decision making between different possibilities
  • Consider different ability levels and strategy types for computer players
Phase 5 - Game Management and Settings

Settings

  • Settings pop up created - COMPLETE
  • Local options (choose team colour, player name etc)
  • Options added - In progress - game speed added, developer tools added
  • Game saving
  • Game rewind / replay
Phase 6 - Rules, roll-out, documentation, testing etc
  • TBDeveloped
Phase 7 - Additional game features
  • Kingdom tax collection ship
  • Develop central market allowing players without resources to trade and fulfill contracts
  • Whirlpools

Contact / Contribute

You can get in touch with me on discord if you would like to contribute.

You can find the current state of the game here:
https://miniature-tiger.github.io/archipelago/

The repository for the project is here:
https://github.com/miniature-tiger/archipelago

Have fun!

Sort:  

Thanks for the contribution, @miniature-tiger!

Very interesting reading about how you implemented the decision making process! Is there anything that inspired you to implement it this way or did you just figure it out along the way?

Also the added images showing the decision making of the ships are a great addition to your post, your commit messages are very descriptive and clear and the quality of your code is high - keep up the great work!

Looking forward to your next contribution! What's the next feature you have planned?

Your contribution has been evaluated according to Utopian policies and guidelines, as well as a predefined set of questions pertaining to the category.

To view those questions and the relevant answers related to your post, click here.


Need help? Write a ticket on https://support.utopian.io/.
Chat with us on Discord.
[utopian-moderator]

Thanks Amos!

For the decision making I thought about some kind of iterative process but there's so much luck in the game that the value of projecting ahead is quite limited, so in the end I just tried to have the computer opponent rank all the possible moves and take the best one. It will need more refinement as there are complexities when the chosen destination is more than one move away. In this situation the path chosen for the intermediary move is the fastest route, which is not necessarily the best route. It also doesn't currently look at situations where there are a group of resources all in the same general area of the board which it would make sense to move towards, so maybe I need to add some value to the rankings for that.

But it's been pleasing as well, in that occasionally the computer will pick out a better move than I would have chosen, just because it's doing a better job of looking at all the resources and working out what is left to be claimed.

So more to refine on the decision making but I'll do that after the contracts delivery process as this is the most complex decision and no doubt will throw up a host of new issues! That's the next step, hopefully within the next week, at which point the main parts of the one player functionality should be in place.

Thank you for your review, @amosbastian!

So far this week you've reviewed 4 contributions. Keep up the good work!

Hey @miniature-tiger
Thanks for contributing on Utopian.
We’re already looking forward to your next contribution!

Want to chat? Join us on Discord https://discord.gg/h52nFrV.

Vote for Utopian Witness!

Hi @miniature-tiger! We are @steem-ua, a new Steem dApp, computing UserAuthority for all accounts on Steem. We are currently in test modus upvoting quality Utopian-io contributions! Nice work!

Coin Marketplace

STEEM 0.29
TRX 0.11
JST 0.033
BTC 63945.57
ETH 3135.76
USDT 1.00
SBD 4.00