Find the uniform search technique for the River Crossing puzzle - artificial-intelligence

I have to use a uninformed search technique to solve the following problem.
The game is like:
On side of the river, there is a Policeman, a Robber, a woman in a red-dress and her two children, a woman in a yellow dress and her two children. There is a boat that can carry atmost two persons. The children cannot drive the boat.
If the policeman is absent then the robber will kill the people. If the red-dress woman is absent then the yellow-dressed woman will kill the red-dressed woman’s children and vice versa.
I am confused as usual. Please help me figure it out.
The problem and how can it be solved (without programming) is shown in the video below:
https://www.youtube.com/watch?v=vSusAZBSWwg
Thank you.

Problems like River Crossing Puzzle, Sokoban or Lemmings are solved normally with Brute-Force-Search in the gametree. The domain is specified declarative as rules (moves are possible or not), and a function which determines the amount of points which are reached by a policy (policy = plan through the gametree). The solver has the aim to find a good policy. The best hardware for doing this is a quantum computer with unlimited speed for testing as much as possble moves per second.
The reason why this is not practicaly is because of a phenomenon which is called "combinatorial explosion", first introduced by James Lighthill in year 1973 for prooving that artifical intelligence is not ready for use in realworld. The answer to that problem is, to use alternative strategies which have noting to do with brute-force-search.
One possibility is to use heuristics which are hardcoded into programcode. Often these heuristics are called macroaction or motion primitives. An example would be "bring-robber-to-other-side". This subfunction executes a predefined number of actions. Another macroaction could be "check-if-two-woman-are-on-the-same-side". To implement such kind of strategy for the complete game is a hard task. Not because of high cpu usage, but because of every detail has to coded into software.

Related

Questions about Q-learning in a 2D maze

I just read about Q-learning and I'm not sure if I understand this correctly. All examples I saw are rat-in-a-maze, where the rat must move towards the cheese, and the cheese doesn't move.
I'm just wondering if it's possible to do Q-learning in a situation where both the mouse and the cheese move (so one agent chases and the other runs away).
If Q-learning doesn't work in that situation, do we have any other algorithms (greedy or non-greedy) that work?
Also is there a formal/academic name the situation? I'd like to search for papers that talks about this but can't find its formal/academic name.
Thank you so much!
All RL algorithms enable a single agent to learn a policy. In problems that involve multiple actors such as a mouse and a cheese, one actor (the mouse) would learn a policy using an RL algorithm and the other actor (the cheese) would be guided by some AI that is not RL. If both the mouse and cheese are RL agents, then you're looking at multiagent RL. Here is a nice framework for it: https://github.com/PettingZoo-Team/PettingZoo/
Q-learning is probably the most popular RL technique for beginners, but can only solve very simple toy problems with a discrete state space, such as a 2D maze. It is not very effective in addressing problems with a continuous state space, even simple ones, such as the Cartpole. It might solve them but would take much longer than other RL methods. Q-learning combined with a neural network, however, can be very powerful, as demonstrated by RL methods such as deep Q-network (DQN) and double DQN.

Tree generation in abalone artificial intelligence

I need to implement an intelligent agent to play Abalone game, for this kind of game the best way to proceed seems a min-max strategy with alpha beta pruning.
I have already implemented a naive search algorithm that use min-max with pruning,
my problem is...
How to generate the nodes of the tree where perform the search?
I have no idea of the right way to do this, and how assign the weigh to each node.
For generating the tree nodes: You need to implement a method that returns a collection of all possible legal moves given the current board position and the player whose turn it is. All these moves will become children of the node representing the current board position. Repeat until memory is exhausted to generate the game tree ;) or rather until you reach a reasonable tree depth.
For alpha-beta search you also need an evaluation function which calculates the weight for each board position/node. You can do some research or think about such a function yourself, maybe considering the number of stones still on the board. However a bad evaluation function can seriously screw up your results, so take care and run a lot of tests.
If you have trouble coming up with a reasonable evaluation function, I recommend you take a look into Monte-Carlo techniques such as UCT.
http://en.wikipedia.org/wiki/Monte_Carlo_tree_search
These tackle the problem using a probabilistic approach and have some nice advantages over alpha-beta. Also they don't require an evaluation function so you could skip this step.
Good luck!
I have published two libraries for move generation in Abalone. You didn't mention the programming language used for your search implementation, but you can easily port the functions.
For C++, https://sourceforge.net/projects/abnet/
For Python, https://gitlab.com/peer.sommerlund/haliotis
For an evaluation function, distance between all your marbles, or distance to their gravity center (same thing), works nicely. Tino Werner used this with a twist for his program that won ICGA 2003.
For understanding distance when using hex coordinates, I can recommend Amit Patel's page: https://www.redblobgames.com/grids/hexagons/

Signal classification - recognise a signal with AI

I have a problem with recognising a signal. Let say the signal is a quasiperiodic signal, the period time has finite limits. The "shape" of the signal must match some criteria, so the actual algorithm using signal processing techniques such as filtering, derivating the the signal, looking for maximum and minimum values. It has a good rate at finding the good signals, but the problem is it also detects wrong shapes too.
So I want to use Aritifical Intelligence - mainly Neural Networks - to overcome this problem. I thought that a multi layer network with some average inputs (the signal can be reduced) and one output whould shows the "matching" from 0..1. However the problem is that I never did such a thing, so I am asking for help, how to achive something like this? How to teach the neural network to get the expected results? (let say I have vectors for inputs which should give 1 as output)
Or this whole idea is a wrong approximation for the problem? I am open to any learning algorithms or idea to learn and use to overcome on this problem.
So here is a figure on the measured signal(s) (values and time is not a concern now) and you can see a lot "wrong" ones, the most detected signals are good as mentioned above.
Your question can be answered in a broad manner. You should consider editing it to prevent it to be closed.
But anyway, Matlab had a lot of built-in function and toolbox to support Artificial Intelligence, with a lot of sample code available, which you can modify and refer to. You can find some in Matlab FileExchange.
And I know reading a lot of technical paper for Artificial Intelligence is a daunting task, so good luck!
You can try to build a neural network using Neuroph. You can inspire from "http://neuroph.sourceforge.net/TimeSeriesPredictionTutorial.html".
On the other hand, it is possible to approximate the signal using Fourier transformation.
You can try 1D convolution. So the basic idea is you give a label 0: bad, 1: good to each signal value at each timestamp. After this, you can model
model = Sequential()
model.add(Conv1D(filters=64, kernel_size=3, activation='relu', padding = 'same', input_shape=(1,1)))
model.add(Bidirectional(LSTM(20, return_sequences=True)))
model.add(Conv1D(filters=64, kernel_size=3, activation='relu', padding = 'same'))
model.add(Dropout(0.5))
model.add(Flatten())
model.add(Dense(100, activation='sigmoid'))
model.add(Dense(2, activation='softmax'))
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
Train the model and then give it a new signal to predict. It will predict given series to 0 and 1 values. if count of 0 is more than count of 1, the signal is not good.

AI Minesweeper project

I need to implement Minesweeper solver. I have started to implement rule based agent.
I have implemented certain rules. I have a heuristic function for choosing best matching rule for current cell (with info about surrounding cells) being treated. So for each chosen cell it can decide for 8 surroundings cells to open them, to mark them or to do nothing. I mean. at the moment, the agent gets as an input some revealed cell and decides what to do with surrounding cells (at the moment, the agent do not know, how to decide which cell to treat).
My question is, what algorithm to implement for deciding which cell to treat?
Suppose, for, the first move, the agent will reveal a corner cell (or some other, according to some rule for the first move). What to do after that?
I understand that I need to implement some kind of search. I know many search algorithms (BFS, DFS, A-STAR and others), that is not the problem, I just do not understand how can I use here these searches.
I need to implement it in a principles of Artificial Intelligence: A modern approach.
BFS, DFS, and A* are probably not appropriate here. Those algorithms are good if you are trying to plan out a course of action when you have complete knowledge of the world. In Minesweeper, you don't have such knowledge.
Instead, I would suggest trying to use some of the logical inference techniques from Section III of the book, particularly using SAT or the techniques from Chapter 10. This will let you draw conclusions about where the mines are using facts like "one of the following eight squares is a mine, and exactly two of the following eight squares is a mine." Doing this at each step will help you identify where the mines are, or realize that you must guess before continuing.
Hope this helps!
I ported this (with a bit of help). Here is the link to it working: http://robertleeplummerjr.github.io/smartSweepers.js/ . Here is the project: https://github.com/robertleeplummerjr/smartSweepers.js
Have fun!

Interprocess communication between multiple AI engines

I want to arrange an AI contest between some friends.
Lets say tic tac toe,
each player program a method which get the board and a symbol(X\O) and return the place which he want to play at his turn.
Now my problem its how to "connect" two AI's in another program so I can test all users and see who has the best code.
The only way I think of is to communicate with a text file - all the AI's have thread running on background and check changes on the text file,the engine summary the game details(which turn,the board,score,players) to the text file.
How can this can be done better?
And one more little thing, this is common to have a time frame for each turn in AI contests?
(Because the AI program will run in different times on different computers)
It isn't clear from your question whether this has to be performed online or not.
If you're after finding "the best Tic Tac Toe algorithm", you could simply:
(This may slightly differ, depending on the programming language)
Define an interface (e.g: ITicTacToeSolver)
Have all your friends implement it in their own way and send you a DLL with their solution.
Create the game which will dynamically load these DLLs, and test them (play 1,000,000 games with the algorithm that is loaded).
Keep track of game statistics to see which algorithm is best.
If the AI programs are competing in a game like tic tac toe, typically every program would have limited total "thinking" time (e.g. 5 minutes), and a program that exceeds its time allotment would lose.
Typically often the programs are connected over some sort of a simple protocol, not through text files. The protocol can run on standard I/O or through TCP/IP sockets.
To normalize CPU usage, you can request that for tournament games, all the programs are compiled to work on a reference platform and then you provide two identical PCs, both running one of the active contestants. It then becomes a requirement of your tournament that the programs can be executed on this reference platform.
Use an interface and a standard programming language - so you can forget about text files and bollocks like that.
Figure out a simple SOAP protocol. You can simply create a WSDL interface - easy to create using windows communication foundatoin (WCF) or JMS.
Easiest would be to have a centralized server to serve as a referee and keep track of time. Each player could be assigned an ID.
Then you could have a the following interface (use WCF or JMS to create a WSDL SOAP protocol)
function int requestGame(int opponentID, int color)
- if called with color = -1, randomly assigns a color and returns it (0=white, 1=black).
- otherwise you can request a color, and returns it if accepted, -1 if not accepted.
- could use -1 to request random opponent.
function int getRemainingTime(int color)
- returns the time remaining on clock for color
function bool play(int color, int i, int j)
where color = 0 - white - 1 black,
i, j are board coordinates,
- returns true if it is a legal move
function bool won(int color)
- returns true if color has won the game.
Not having a centralized server would be more complex since they would have to negotiate over agreed wins, time, etc.
I would suggest to have each of the AI be executable files, communicating by using standard input and output. The game engine (the referee) would send the complete state of the world to AI_one as input, then wait for a move from standard output. It would then perform the move (if legal) and repeat the process for AI_two, then alternate between the two until the game is over. As a failsafe the referee can make one side lose if it takes too long to make a move.
This method is used by Google AI challenge.
One very big advantage to this approach is that people can write their AI in different languages, as long as they follow the agreed standard for how to make a move.
If your goal is to have an AI programming competition amongst friends, I'd suggest that you don't waste time designing and implementing the framework for holding the competition. Use something that already exists for that purpose. You can skip all the pain and heartache of fixing bugs in your framework and get right to the fun part: developing AI.
A good framework is the Robocode game. Watching your robots kill each other will be a lot more fun than watching them play tic-tac-toe.
You should take a look at this question:
What is the best Battleship AI?
In it he creates a battleship AI contest / challenge. It was very high rated and a lot of fun to code for and watch.
He used the Tournament API http://tournaments.codeplex.com/ to run the competition.
Also, it's important to allow the submissions to compete multiple times.. ie 1000 times each. This removes alot of the randomness and luck from the competitors.

Resources