Bejeweled Blitz - How does it assert there is always a move? - mobility

I have been playing Bejeweled Blitz for a while now. Yes, it is an addiction. In thinking about the game, I have observed that on some boards, the bottom runs dry (no moves) leaving only the top part of the board playable. Frequently that part of the board drys up, and one is left with moves in area cleared by the last move.
The board never runs completely dry, so clearly the program is doing some sorts of calculation that allows it to choose what to drop to prevent it from running dry.
I have noticed in this 'mode' that it is very common for the algorithm to drop jewels which causes more non-dry area to appear in the horizontal area. Perhaps less frequent is a drop which seems designed to open up the bottom part of the board again.
So my question is "How would one go about designing an algorithm guarantee that there is always a move available.?"

I wrote three-in-a-row game a while ago and the way I dealt with that problem is by selecting gems to drop at random and counting all valid moves. If selected gems did not provide at least 1 valid move I would select another set of gems and so on.

This is solvable by exploring the space of possible "jewel drops" and then you apply a rating based on your rules you have asked for. Higher rating could mean follows rule and low ratings mean not following then you choose one slot with the highest rating.
This is not easy to explain, but a rule based approach should do the trick.

Related

Is there an optimal depth in a game tree?

I'm working on this game engine which plays some board game, I implemented minimax with alpha beta pruning, and move ordering. Now when I play with other existing engines, everything looks fine. However, I found two subtle problems which I don't know what causes them, maybe I have some gap in my knowledge.
The first issue:
When I increase the depth of the search, intuitively I should get better results even if consumes more time, but in my case moving from depth 8 (winning) to depth 9 causes me to lose all the time, now if I increase it to 10 I suddenly win again. Keep in mind that I keep everything constant except the depth. At first I thought that maybe its because at depth 9 we find a promising move at first which the opponent can refute it easily, but then this could happen at every depth. So my question is what causes this weird behaviour? Is there an optimal depth, which if we go beyond could backfires?
The second issue:
Its similar to move ordering but done to get the values of the next play to pick what to play. For example:
For every possible move starting from weakest move do:
minimax(move)
Now since we have to go through all possible moves why having the strong moves first wins the game but if I started with the weakest moves loses the game. It doesn't make since we have to evaluate all possible moves anyway. What causes this behaviour?
When I increase the depth of the search, intuitively I should get
better results even if consumes more time, but in my case moving from
depth 8 (winning) to depth 9 causes me to lose all the time, now if I
increase it to 10 I suddenly win again.
Certainly sounds like a bug to me.
For every possible move starting from weakest move do:
minimax(move)
You should always start from the strongest move in order to benefit from alpha-beta pruning
Now since we have to go through all possible moves
What about alpha-beta pruning? You do not have to go through all possible moves.

How do we run multiple cases in labVIEW?

Im working on running traffic lights on four cases by using case structure and Flat-sequence structure. For example, there is green light on first case, and the rest of the three cases should have red light. As soon as the first case approaches to red light, the second case moves towards the green light. All these are controlled by specific time delays. The flat sequence structure is running the traffic lights properly in all the four cases, but, when I insert case structure, it only runs one case and does not activate the other cases. How can i make the VI run all the four cases simultaneously??
First off, this is an old CLD exam. There should be a wealth of examples available from a quick search. That said, some suggestions: never use a flat-sequence structure. Ever. Instead you need to use some combination of a state machine and subVIs. NI has a prep kit for the CLD (below). Check it out, it’ll show you what a state machine is in LabVIEW and how to take advantage of subVIs.
http://www.ni.com/gate/gb/GB_EKITCLDEXMPRP/US

Negamax freezes

In a game I've created Negamax works well for low depth searches but larger depth increases causes it to freeze. I thought about changing depth to type 'long' instead of 'integer' but not sure what else I can do. I know computation will take longer so it is possible it is calculating behind the scenes and I'm interpreting as freeze up. Any advice would be appreciated. In the game a player can only make 1 of 3 possible moves in a position and it is not like chess where there are large numbers of moves possible in anyone position and terminal position is difficult to reach.
Thanks
Daz
What counts as larger depth?
Remember that these trees grow exponentially, so if you have 3 options on the first choice, you have 9 when you're 2 deep, 59049 options to check when you're 10 deep, and so on. Another possible reason for things to slow down drastically is if you start using the page file; that is if you're storing your whole tree and suddenly run out of Ram once you get to a "larger" depth. You can probably hear that, or see the blinking hard drive light, if that's contributing.
Your best bet is to get some feedback; get it to print out a new number every x thousand options it checks, so that you can find out instead of guessing at whether it's still trying and how far it has to go. Once you know what it's doing and assuming it is just munching through, look into something like alpha-beta pruning to prevent the tree from growing as quickly.

Can this online highscore scheme be abused?

Background
One problem with games using online highscore lists is that they often can be abused. The game sends the current score to the server and a cunning user can analyze the protocol/scheme and send bogus scores. That is why some highscore lists are topped with 999999 scores.
A common solution to this problem is to encrypt the score in some way, and on top of that put other mechanisms to recognize false scores. But even if you do this, it's the client that sends the score and the client is living in the user's computer and can be reverse-engineered.
My idea
I am designing/thinking about a game (that I will complete, yeah right :) ) where you configure your player/robot with instructions on how to perform a task (and when these instructions are to be carried out). When a "Go" button is pressed the game runs the instructions. Finally a result and, if successful, a score, is obtained.
So, how about this: Instead of submitting the score, the actual instructions are sent to the server, where they are run, using the same implementation. Then the server calculates the score and places the user on the highscore list.
The question
Are there ways this idea can be abused to get a false score?
I understand that this probably is not a new idea. But if it works, it wouldn't be impossible to extend it to other games too, where it is possible to record all user actions.
People will always find a way to cheat, but this seems like a reasonable counter measure. You'll have to consider your intended traffic levels as your scheme will require more resources than if it was just recording the high score sent by the client.
But, as an aside - this game sounds an awful lot like my job (giving instructions to a machine so it performs some task). No high-score board though (although, that would be awesome).
as long as the robot program's behavior doesn't depend on the speed of the computer it'll be fine and if the programs are quite small at most a few kilobytes this would work fine; the only way i can see to cheat it is if one cloned the work space and ran a program to find the optimal program for the robot and then put it in and submitted it or if some one posted the solutions, and people used that but both of those issues can be solved with randomization.
(a note about the issue of speed dependent games, it's fine for the game to uniformly slow down if the computer can't run it at full speed but if the physics time step depends on the frame rate, you can get problems like the jump height varying with the frame rate)

I am looking for a radio advertising scheduling algorithm / example / experience

Tried doing a bit of research on the following with no luck. Thought I'd ask here in case someone has come across it before.
I help a volunteer-run radio station with their technology needs. One of the main things that have come up is they would like to schedule their advertising programmatically.
There are a lot of neat and complex rule engines out there for advertising, but all we need is something pretty simple (along with any experience that's worth thinking about).
I would like to write something in SQL if possible to deal with these entities. Ideally if someone has written something like this for other advertising mediums (web, etc.,) it would be really helpful.
Entities:
Ads (consisting of a category, # of plays per day, start date, end date or permanent play)
Ad Category (Restaurant, Health, Food store, etc.)
To over-simplify the problem, this will be a elegant sql statement. Getting there... :)
I would like to be able to generate a playlist per day using the above two entities where:
No two ads in the same category are played within x number of ads of each other.
(nice to have) high promotion ads can be pushed
At this time, there are no "ad slots" to fill. There is no "time of day" considerations.
We queue up the ads for the day and go through them between songs/shows, etc. We know how many per hour we have to fill, etc.
Any thoughts/ideas/links/examples? I'm going to keep on looking and hopefully come across something instead of learning it the long way.
Very interesting question, SMO. Right now it looks like a constraint programming problem because you aren't looking for an optimal solution, just one that satisfies all the constraints you have specified. In response to those who wanted to close the question, I'd say they need to check out constraint programming a bit. It's far closer to stackoverflow that any operations research sites.
Look into constraint programming and scheduling - I'll bet you'll find an analogous problem toot sweet !
Keep us posted on your progress, please.
Ignoring the T-SQL request for the moment since that's unlikely to be the best language to write this in ...
One of my favorites approaches to tough 'layout' problems like this is Simulated Annealing. It's a good approach because you don't need to think HOW to solve the actual problem: all you define is a measure of how good the current layout is (a score if you will) and then you allow random changes that either increase or decrease that score. Over many iterations you gradually reduce the probability of moving to a worse score. This 'simulated annealing' approach reduces the probability of getting stuck in a local minimum.
So in your case the scoring function for a given layout might be based on the distance to the next advert in the same category and the distance to another advert of the same series. If you later have time of day considerations you can easily add them to the score function.
Initially you allocate the adverts sequentially, evenly or randomly within their time window (doesn't really matter which). Now you pick two slots and consider what happens to the score when you switch the contents of those two slots. If either advert moves out of its allowed range you can reject the change immediately. If both are still in range, does it move you to a better overall score? Initially you take changes randomly even if they make it worse but over time you reduce the probability of that happening so that by the end you are moving monotonically towards a better score.
Easy to implement, easy to add new 'rules' that affect score, can easily adjust run-time to accept a 'good enough' answer, ...
Another approach would be to use a genetic algorithm, see this similar question: Best Fit Scheduling Algorithm this is likely harder to program but will probably converge more quickly on a good answer.