The Tequila Den

Combines the world of Tequila with Games.

Tag Archives: google

Finally got it…

At least, I think I do. I thought I had it all figured out before hand, but then a bug came out. A nasty little bastard that basically crippled the damn game.

Okay, that’s a bit extreme. The game is fine without it, but the problem was though you wouldn’t be credited with your feat unless you kept building and hopefully it picked the right set, sigh. Yup, longest road issues struck again.

I scoured the crap out of my code and found a slight oversight. My first “correct” stab at the process had all the roads tied together with it’s only possibility. Thus, if a player does place all 15 of their roads. The code would flip through each road and see if it can find it’s little soul-mate. So essentially what I thought I created was a set of road segments that could only go together. The problem was that once you see that particular set from the other end, it’s a cheating bastard. So what I thought I had wasn’t what I had at all. Re-write time.

I googled and lou-oogled (hot tub time machine, great movie,) around the web about how people have been implementing Catan’s longest road and really I have seen a lot of forum/blog posts about the situation. None of which I’ve been able to successfully implemented in Javascript. They did however spark my brain and come up with a valuable solution to the issue at hand. The biggest issue I had with the process was how do I loop through the same set of roads twice, without repeating myself and going through a loop I have no idea how to stop or how many times it’d have to iterate as the list of possibilities grew exponentially as the amount of roads were being added. God forbid the player built “trees” and “circles” out of their roads. Headaches ensued.

The solution to world hunger… err…. finding the Longest Road in Catan, pseudo-style.

Take all roads and toss them into an array by themselves.
//roads[x] = the entire chain, r1,r2,r3 ; roads[x][y] = road in roads[x] in pos. y, r1.

Keep track of the ends of each of these roads, represented by settlement spots (which I refer to as corners) in an array that correlates to the roads’ array.
//ends[x][y] = x is equal to the x in roads, y = is the ‘left’ & ‘right’ of the roads’ x.

Set maxMisses to the amount of roads and misses to zero, and make to false.
//this is the control to see if a new chain of roads were created.

while (misses < maxMisses) Loop through all of the player’s roads. Loop through all the chains that were made. If the current road in the loop isn’t in the current chain, proceed, Now, if the current road links to the current chain and it’s not already in that chain,
– Clone the current chain along with the ends of that chain.
– Add the current road to the cloned chain  and update the new ‘ends’ of the chain, add to the database of chains.
– set make to true. end the loop of the chains.

If the make is false, misses++, otherwise it’s set back to zero. end all loops… That will give you all the possible set of chains for the given player’s roads. It amounts to a bunch of roads, many of which are duplicate of themselves. This is because of the starting points of the roads; do remember that we clone each time we add a new road. They can easily be filtered out afterwards by seeing if the length is greater than 4 (Catan rules), you can eliminate more if you’ve stored the current longest road.

You can always comment / email me if you’ve got questions about my implementation or if you want to see some code. (Warning, I’m not a pro-scripter by any means and some stuff is kind of messy, and not exactly ‘efficient’.) Next time, how to see if the chain has been interrupted by an opposing settlement/city.

Advertisements

Cleaning out my closet.

Well, its more of a room really. Been hard at doing some daily chores the last couple of days, could be because of having the last couple of them off from work. Its been delightful having the time off, especially since I’ve made a bit of progress on Traders, which I’ll discuss later.

First off, I was cleaning out a bit of a junk room. Mainly all the stuff that really didn’t fit anywhere else, old paperwork, boxes of stuff I haven’t touched in a while, extra tools and mainly my desktop computer. Any who, I stumbled upon my collection of Star Wars CCG cards. So, respectfully, I catalogued them, then did the unthinkable, I tossed out my doubles. I never really thought I could. But it really felt like I was letting go of my childhood a bit. I was okay with it. The one thing I couldn’t find was my Magic cards. I’m not entirely sure where the hell those are. Hmm… the days when Magic was simple. I can’t even remember how to play. I almost bought a few packs just to bring back some nostalgia. I woke up a bit and remembered that I wouldn’t really touch them, I wouldn’t know which ones were valuable and I’d have no one to play with. If I could find packs of the first few sets I’d buy those in a heartbeat. (Opens Google search…)

Oops, anyway, found out I played in roughly the 3rd edition era, perhaps even a little bit before that. Playing POG and Overpower as well clouds my memory. I don’t even remember how to play OP either, I just remember it was super simple and there was a Reserve character. I couldn’t find my Batman either… damn it.

Anyway, back to Traders. I’ve spent the last couple of days re-factoring it and making the game smoother. I’ve moved the players’ information to the right spot which was once occupied by the chat section. I then moved the chat to the top of the screen and can (well, will be) be opened/collapsed by pressing the ’tilde’ (~).

I’m pumped to get this game out of my hands. Soon enough, soon enough…

Actually updated yesterday, but today is a new day.

Yesterday, if anyone has actually snooped around (which I don’t think anyone visits,) you would have noticed that I placed a couple of new screenshots in the CCCCC page. One of the images was one that I made simply as a debugging tool, just a few lines of simple code to place the numeric references I use on the map in their proper location. I use that as a means of creating certain algorithms in the game.

Now, however, I’ve been dealing with the longest road. This no doubly has been the biggest pain in my head. And ass. I’ve wasted countless sheets of paper trying to devise the best possible way to go about, but right now, to no avail. This kind of reminds me of doing Canasta’s AI and thought process. It reminds me that this is going to be a headache. Damn.

I’ve actually reached out to Google a few times but their methods don’t make a much of sense to me. They’re all geared towards crazy geek-Dom (I’m thinking C talk, methods). I do not comprehend any of that. I’m not sure how to do the methods they talk about in JavaScript, and honestly, I don’t want to look and learn either. (unless I unfortunately get to that point).

I’ve made lots of other bug fixes in the process. Everything else seems to be at par for now. We’ll see how this other ‘headache’ comes to be.

screenshot 2013.10.29 17.19.02.0328

screenshot 2013.10.30 18.37.51.0031