Share Wars - Have fun bankrupting your friends!

Merging of corporations is finally done

This took quite some time, but it was worth it. The game is in general in a much better shape now.

When a merger happens, the game has to …

  • decide who is the buyer. The corporations involved are ranked based on their worth. The worth of a corporation is the number of tiles (the market share) multiplied by the share price. The most valuable corporation is the buyer.
  • group the selling corporations by share holder.
  • ask each player what to do about their shares. The list of selling corporations are passed to each player so that they can validate each one, and return their decisions.
  • lastly, the game mode acts on the player’s decisions

I found that the player code became more easy to reason about when it’s only about reading state data, and returning a decision, not actually performing the changes. A decision is usually in the form of an enum.

For deciding what to do about the selling corporations, the player code looks something like this:

func merge(buyer: Enums.CorpType, sellers: Array[Enums.CorpType]) -> Dictionary:
    var result = {}
    for seller in sellers:
        # when player wants to sell all shares
        result[seller] = Enums.Merge.SellAll
        # when player wants to trade
        result[seller] = Enums.Merge.Trade
    return result

The calling code expects to get a Dictionary in return, with the CorpType as key, and the decision as a specific enum. I use this way of handling player decisions for all actions, placing tiles, merging corporations, trading shares and ending the game.

Aside from simplifying the player code, it also ensures that the game mode is in control over when things happen, and can ensure that nothing happens out of order.

AI vs AI

For as long as I can remember, gamedevs have called their NPC’s intelligense AI. Now that AI can be ChatGPT, Midjourney and loads of other things, I’m not quite sure what term to use. Anyway, just for fun, I swapped out my local player object with another instance of the AI (called Archie), to see what would happen when they play against each other.

sharewars_ai-vs-ai_01

This was not only fun to watch, but also a handy way of testing the game.

  • I learnt that I hadn’t implemented the game over state. The game crashed when it reached the end. New task added to the task list.
  • I can clearly see that the game needs more work on balancing the share and dividends values. Not surprising.
  • It seems like the function that returns a random chit makes a pattern. Should probably look for a different random function.

Civilization graph

Later, when I get to implement the graph for tracking the player worth (like Civilization does), I can see how different AI’s perform against each other, and use that to make more informed changes to their strategies.

The next steps

  • Implement the game over state. Make it possible to end the game, decide a winner, show it to the player.
  • Make sure the code cleans up after a session, so that a new one can be started.
4 Likes