Author Topic: Project 1A: Carcassonne Game Notation  (Read 12299 times)

Offline wallaceprime

  • Nobleman
  • ******
  • Posts: 125
  • Merit: 53
  • I'm skillful, you're lucky! ;-)
    • View Profile
    • Wallaceprime's photo gallery
Re: Project 1A: Carcassonne Game Notation
« Reply #75 on: June 15, 2022, 05:37:01 AM »
I think a “clean” landscape would be much easier for image processing.  Are you using openCV?  Some other library?

I'm brute-forcing it in C++.
I take the following steps:
  • capture the screen
  • do a maze-walk to find the periphery of the playing area
  • search for a couple of dark grey tile placement positions (so I can find the tile size)
  • calculate the tile boundaries in the playing area
  • reduce each tile position to a 5 x 5 pixel matrix leaving a small border to allow for pixel misalignment
  • compare each reduced tile to a list of all 2116 tile/orientation/meeple combinations (just for the base game at the moment) to find the best match

Here's a composite image of all the 5x5 pixel combinations!



It wouldn't be of any use at all for analysing photos of games played with real tiles on a table; I can't imagine players reacting to well to repeatedly being told that "you can't put the meeple on that side, it expects it on the other" or "well that doesn't work, your meeple is 2 mm away from the optimal position" and so on  ;)
« Last Edit: June 15, 2022, 06:23:41 AM by wallaceprime »
Never too old to learn new tricks

Offline wallaceprime

  • Nobleman
  • ******
  • Posts: 125
  • Merit: 53
  • I'm skillful, you're lucky! ;-)
    • View Profile
    • Wallaceprime's photo gallery
Re: Project 1A: Carcassonne Game Notation
« Reply #76 on: June 15, 2022, 06:10:02 AM »
I originally tried looking at various locations within a tile to decipher whether it was city, road or field, but it got really tricky when a meeple almost occluded visibility of the small segment of road it was placed on, such as with a CCCR tile (so it couldn't tell if it was a farmer on a CCCF or a road meeple on a CCCR) or similarly with a RRRR being interpreted as a farmer on a RRRF tile.

I'm surprised I've got any hair left at all after all the hair-pulling that all those tweak/test iterations took! Comparing all 25 pixels seem to have worked flawlessly so far; I expect the slightly different layouts make enough difference for the matching to differentiate between them.

Offline DIN0

  • Viscount
  • ****
  • Posts: 837
  • Merit: 37
  • Carcassonne is only complete with 11th expansion:)
    • View Profile
Re: Project 1A: Carcassonne Game Notation
« Reply #77 on: June 15, 2022, 06:41:44 AM »
Quote
but it got really tricky when a meeple almost occluded visibility of the small segment of road it was placed on,
You could either make meeple substitutes, or even better clear elevated stands for meeples.

Offline kothmann

  • Viscount
  • ****
  • Posts: 804
  • Merit: 92
  • Oh! That’s interesting...
    • View Profile
Re: Project 1A: Carcassonne Game Notation
« Reply #78 on: June 15, 2022, 10:01:53 AM »
Here's a composite image of all the 5x5 pixel combinations!
WOW!  This is fantastic!  Thanks for sharing.

Offline wallaceprime

  • Nobleman
  • ******
  • Posts: 125
  • Merit: 53
  • I'm skillful, you're lucky! ;-)
    • View Profile
    • Wallaceprime's photo gallery
Re: Project 1A: Carcassonne Game Notation
« Reply #79 on: June 16, 2022, 01:22:50 AM »
To find tile boundaries, I originally used a hue, saturation and value test to see if a pixel was a tile or not. Unfortunately, it got confused by meeples that hung over the edge of a tile; indicated with red circles below:



Rather than looking at every pixel, I used recursion to find the edges of the tile placement positions, where the function that tries to find a corner initially starts with a step size of 16 pixels, but then calls itself with half that step size when it overshoots. This way, if the edge was 63 pixels away for example, instead of checking all 63 pixels, it would only check at positions 16, 32, 48, 64, 56, 60, 62 and 63, so at just 8 positions. The tricky bit was tailoring the algorithm to ignore when meeples overhang the edge of tiles, looking ahead to see if it went back to being the background.

Ultimately, however, it was easier just to look for the dark grey placement positions:



I could then pick a couple and look for the smallest dimension and that was the tile size. I did have to go one step further, however, because BGA must calculate the corner positions in floating point, but then use them in integer form. This had the effect of sometimes causing tiles sizes to fluctuate between two integer sizes, such as between 54 and 55 pixels. This meant I couldn't rigidly use one size as, going across the playing area, the error would increase sufficiently to throw the tile boundaries off.

If any of you find this sort of stuff interesting, I'll create a new subject for it, but I know it's not everyone's cup of tea and I don't want to distract here from @DIN0's sterling work on his notation projects.
« Last Edit: June 16, 2022, 01:31:25 AM by wallaceprime »

Offline DIN0

  • Viscount
  • ****
  • Posts: 837
  • Merit: 37
  • Carcassonne is only complete with 11th expansion:)
    • View Profile
Re: Project 1A: Carcassonne Game Notation
« Reply #80 on: June 16, 2022, 03:03:47 AM »
Quote
If any of you find this sort of stuff interesting, I'll create a new subject for it, but I know it's not everyone's cup of tea and I don't want to distract here from @DIN0's sterling work on his notation projects.
Please do. This definitelly deserves its own topic. This is some interesting stuff you are working on! I'll be watching the progress with great interest :(y)


Share via delicious Share via digg Share via facebook Share via furl Share via linkedin Share via myspace Share via reddit Share via stumble Share via technorati Share via twitter

  Subject / Started by Replies / Views Last post
clip
Carcassonne game notation system for tournament play

Started by DIN0

32 Replies
9718 Views
Last post September 29, 2019, 03:38:59 AM
by Meepledrone
xx
RCA project. the CAR translated in italian

Started by aenima

12 Replies
7299 Views
Last post August 10, 2016, 02:38:27 AM
by TedPoley
xx
My Latest Video Project...

Started by danisthirty

6 Replies
7619 Views
Last post May 13, 2014, 04:59:00 AM
by danisthirty
xx
Kickstarter project: Carcassone collection box?

Started by Guesclin

35 Replies
28082 Views
Last post February 15, 2015, 02:41:55 PM
by Whaleyland
xx
Superbowl Sunday: 2-player game (base game + I&C)

Started by Scott

4 Replies
9133 Views
Last post January 31, 2015, 10:36:40 AM
by Scott