Archipelago - Computer Opponent Automation


Introduction

The last Archipelago post saw phase 2 (Resources, Goods, Building, Trade Contracts, Scoring) and phase 3 (Conflicts and Pirate ships) brought to completion. Over the last couple of weeks I have started on phase 4 - One Player Version Development.

This contribution covers the first stage of the computer player development. The development took the following path:

  • Set up of computer opponents.
  • Getting all computer opponent ships moving.
  • Returning battle-damaged ships to safe harbours for repair
  • Discovering and claiming resources
  • Searching for resource pieces



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

Set up of computer opponents

The first step for computer opponent automation. A new object automove.js was created as the starting point for the computer game logic (so there will now be human, computer, and pirate game logic objects).

The code changes for the above new feature can be found here:
https://github.com/miniature-tiger/archipelago/pull/89/files

The main changes were in the new object automove.js. Methods were written to generate and update the array of all computer opponent ships and to manage these computer opponent ships, i.e cycling through each ship on the board.

The game settings in gamemanagement.js were also updated: three teams were set as computer opponents and one as human, and some event handling was added to prevent players manually moving computer opponents.

Getting all computer opponent ships moving

The next (and trickiest) step was to get all the ships moving according to the basic game rules. The manual and pirate ship game logic provided the starting point for this development with each ship move based on an initial search for all possible moves in wind range (tile activation) and then a choice being made between those potential moves. Initially this choice was simply to move the furthest distance for the lowest move cost.

The code changes for the above new feature can be found here:
https://github.com/miniature-tiger/archipelago/pull/90/files

The main changes were in automove.js. A new method (computerMove) was created with the game logic for decision making and moving the computer opponent ships.

Returning battle-damaged ships to safe harbours for repair

The simplest decision making for computer opponent ships is when ships are damaged. A fairly good rule to start with is that these ships should immediately head to the nearest harbour for repair.

As the computer opponent automation develops this rule may be adapted for additional complexity but for most levels of opponent this approach should be sufficient.

Here's the computer opponent limping home:




Returning to port for repair.

The code changes for the above new features can be found here:
https://github.com/miniature-tiger/archipelago/pull/91/files

The main changes were in automove.js. The "Deciding move" section of computerMove incorporates the logic for the above change.

Discovering and claiming resources

When ships reach new islands, resources are revealed. This change focuses on automating the decision to claim those resources by computer opponents. The simple approach adopted initially is for a computer player to claim the resource if they do not already possess this piece. This takes place at the end of the move in case the player has two ships and both reveal the same resource.

The code changes for the above new features can be found here:
https://github.com/miniature-tiger/archipelago/pull/92/files

The main change was the creation of a method (decideClaimResource in automove.js) to check whether there are resources to be claimed by computer opponents and decide whether a resource should be claimed.

Searching for resource pieces
This changes focuses on the decision making relating to the search for resource pieces. Potential destinations on the map are ranked using criteria such as:

  • revealed resource or undiscovered island
  • number of potential discoveries
  • number of moves to reach island

The highest ranked option becomes the move choice.

In the game below the red computer opponent initially chooses to move east to search the two undiscovered islands at once. This choice is optimal over the other six potential harbouring points around these islands. A clay resource is discovered and claimed.

In the following move only one of the collection of islands can be reached at any one time. A clay resource is again discovered but cannot be claimed as this piece is previously held by the player.


RedResourceSearch.gif

Searching for resources.

The code changes for the above new features can be found here:
https://github.com/miniature-tiger/archipelago/pull/93/files

The main change was the creation of a method (rankDestinations) to rank the potential destinations across the entire map.


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
  • 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
  • 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:  

What i can suggest is to use more .forEach instead of for loops, enums, and helper functions to stay DRY and increase overall code readability.

Great job anyway, keep going.

Thanks @adasq, I'll look into these. The enums look like a good solution in particular. Typically I find I can always get things to work one way or another but I often find myself thinking there must be a cleaner way to do things. Still lots to learn when it comes to coding style!

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]

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!

Glad to see this coming to fruition!

Coin Marketplace

STEEM 0.28
TRX 0.13
JST 0.032
BTC 60870.66
ETH 2917.09
USDT 1.00
SBD 3.62