Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I would like to write a predicate for tic-tac-toe game, that generate possible successor board configuration for given player and board. After typing this input:
next_board([[x,o,x],[x,x,o],[o,e,e]],x,N).
the output should be displayed as following:
N=[[x,o,x],[x,x,o],[o,e,e]];
N=[[x,o,x],[x,e,o],[o,x,e]];
N=[[x,o,x],[x,e,o],[o,e,x]];
To generate possible successor boards you basically have to "replace" single empty cells (marked with e) with your player chip.
At first sight you might be tempted to use select/4 but it would replace every empty cell in a row with your player chip. So, you might be better off using append/3 predicate with something like this:
next_board(Board, Player, NextBoard):-
append(Head, [Row|Tail], Board), % Take a single row from the board
append(RowHead, [e|RowTail], Row), % Take a single empty cell
append(RowHead, [Player|RowTail], NRow), % and replace it with your player chip
append(Head, [NRow|Tail], NextBoard). % Now build a next possible board
You might as well make recursive procedures to achieve the same logic without using append/3.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 months ago.
Improve this question
What is the meaning of this command in Prolog's commanf line? What does time and what does time(ids)?
?- time(ids)
Prolog lists are singly linked lists and it's more convenient and more performant to prepend things on the front instead of append them on the end. A common technique is to build a list backwards, then reverse it. Slago is doing that.
The search starts with the Start state in the list, prepends intermediate states, and finishes when goal(State) holds and the state at the front of the list is the solved puzzle.
Context: https://stackoverflow.com/a/67645940/
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I almost wrote a snake game, but I still can’t get one of the main ideas.
I would like for random walls to appear on the map during the game, as it happens in google snake game in wall mode. Here is the link to game.
My question is only about the idea of the algorithm and it's disconnected from a specific programming language.
The problem is that absolutely random walls could create “unreachable” places in the level, such as enclosed spaces, where the snake could not get theoretically. So how to check such "unreachable" places on a level and not create incorrect walls?
PS: Sorry for my poor English.
Just do a google search for the "A*" Algorithm. The head of the snake is your starting point, the apples your end point and the walls your obstacles. (of course you would have to think about, how to get around the problem of interfering with your tail)
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
So when using, for example, rand(10), how does ruby generate the random number? I have very little knowlege about random number generation techniques, so I would like to get to know them better.
Ruby is open-source. I'll demonstrate how to locate the PRNG (pseudo random number generator) code, as there's no way to generate truly random numbers using a deterministic CPU.
Looking at the repository, we see a suspiciously-named file, random.c. Looking inside, it's in C, but that's ok, it has comments. The first function is genrand_real, calling genrand_int32, which takes a struct MT. This function is defined in mt19937.c and looking at that file, it uses bitwise operations to get the next state of the random number generator and applies more bitwise operators to generate the number desired.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I want to enhance my image by using pso based gray level image enhacment.I send the algorithm but i dont understand how I get particle of my image.pso paper
You only need to carefully read the section B. Proposed methodology. It says something like this:
Now our aim is to find the best set of values
for these four parameters which can produce the optimal result
and to perform this work PSO is used. P number of particles
are initialized, each with four parameters a, b, c, and k by the
random values within their range and corresponding random
velocities.
So there you have your particle generation. Each particle is a set of 4 random values.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
In order to support users learning English, I want to make a multiple-choice quiz using the vocabulary that the user is studying.
For example, if the user is learning "angel" then I need an algorithm to produce some similar words such as "angle" and "angled"
Another example, if the user is learning "accountant" then I need an algorithm to produce some similar words such as "accounttant" and "acountant", "acounttant"
You could compute the Levenshtein Distance from the starting word to each word in your vocabulary and pick the 2 or 3 shortest ones.
Depending on how many words are in your dictionary this might take a long time though, so I would recommend bailing out after a certain (small) number of steps - i.e. if you have made 3 mutations and still haven't arrived at your target word then stop and move on to the next one.