Write a prolog predicate print state

Assignment Help Computer Engineering
Reference no: EM13316811

Your representation should be an internal representation used for evaluating positions in the game; it should not be the external representation shown in the pictures and used for communicating with a human player. You should note that states (a) and (b), as well as states (c) and (d), are equivalent to each other for the purpose of playing the game. (a) and (b) are equivalent because the cells that
are shown in blue and yellow have no subsequent e ect on the play of the game. (c) and (d) are equivalent because the ordering of the groups of unmarked cells also has no e ect. Your representation should represent equivalent states by identical terms.

In the remaining questions state means internal state.

 Write a Prolog predicate print state(X) which will print a state X to the terminal using an asterisk to represent a markable cell and a space to represent a gap between runs of markable cells.

 Write a Prolog predicate next(S,T) which will succeed if T is a state of the game that can be reached from S in one move. Backtracking should generate all such states T, and findall(T,next(S,T),U) should unify U to the list of all of these states.

Also write a predicate print next states(S) which will use your next predicate to nd and print out all states obtainable from S in one move.

 Write a Prolog predicate win(S), which will succeed for any game state S which is a winning position for the player to play, and will fail otherwise. win(S) is found to be true or false by a depth- rst search through the game tree. You should, if you can, make use of the assert
predicate to avoid the search exploring any position more than once (which will greatly speed it up).

Two tests you can use to check that your predicate is giving the right answers are that a run of markable cells of any odd length is always a win for the rst player, while a state consisting of two groups of markable cells of the same length is always a loss for the rst player.
Write a predicate test value(N), which will apply your win predicate to each of the starting states corresponding to boards of size 1; 2; : : : ;N and print a 1 if the predicate win succeeds and a 0 otherwise. For example:

?- test_value(60).
111011101111101111101110111011111011101110111111111110111011 true.

Write a Prolog predicate choose move(S,T), which will choose a winning move for a player faced with the position S, if there is one, the resulting position being T. Backtracking should generate all winning moves. If there are no winning moves the predicate should fail.

Write another Prolog predicate show winning moves(S), which, by using choose move, prints out all of the winning moves for the player whose turn it is to move from position S.

Write a predicate test winning moves(N), which will apply your show winning moves predicate to each of the starting states corresponding to boards of size 1; 2; 3; : : : ;N, printing out both the board size and the winning moves (if any) from that state. For example
?- test_winning_moves(20).
1 :empty
2 :empty
3 :empty
4 :
5 :* *
6 :****, * **
7 :****, ** **
8 :
9 :*** ***
10 :********, * ******
11 :********, * *******, ** ******, **** ****
12 :** *******
13 :***** *****
14 :
15 :**** ********, ****** ******
16 :**************, ****** *******
17 :**************, *** ***********, ***** *********, ******* *******
18 :*** ************, ***** **********
19 :******** ********
20 :
true.

here empty means a winning move without any cell left to mark for the next player, a blank ne means no winning move, and commas separate winning moves.

Reference no: EM13316811

Questions Cloud

Determine maximum compression of spring mounted on car : The 30-Mg freight car A and 15-Mg freight car B are moving toward each other with the velocities VA= 20 km/h to the right and VB= 10 km/h to the left. the spring constant on car A is k= 3MN/m.
What will your speed be at the bottom of the hill : You notice you are running low on gas in your 1200kg car, and you are hoping you have enough gas to reach the bottom of the hill. what will your speed be at the bottom of the hill
Determine what is kinetic energy of the object at the time : A 6.22-kg object passes through the origin at time t = 0 such that its x component of velocity is 5.45 m/s and its y component of velocity is -2.88 m/s. (a) What is the kinetic energy of the object at this time
What would be its kinetic energy per molecule : At 2500K hydrogen gas (H2) adds two more degrees of freedom to its motion. It has three translation motions, two rotational motions, What would be its kinetic energy per molecule
Write a prolog predicate print state : Write a Prolog predicate print state(X) which will print a state X to the terminal using an asterisk to represent a markable cell and a space to represent a gap between runs of markable cells.
What is the magnitude of the horizontal impulse : Catapult fires an 800-kg rock with an initial velocity of 100 m/sat a 40° angle from ground. What is the magnitude of the horizontal impulse
What would the mean and variance of cx be in terms of e : If the mean and variance of discrete random uniform random variable X, are E(X) and V(X) respectively, what would the mean and variance of cX be in terms of E(X) and V(X) if c is a constant
Find the rate of entropy increase : On a cold winter's day heat leaks slowly out of a house at the rate of 25.0kW. find the rate of entropy increase
Compute the work done on the lead shot : After inverting the tube 100 times, the temperature of the lead shot is found to have increased by 30C. Calculate the work done on the lead shot

Reviews

Write a Review

 

Computer Engineering Questions & Answers

  Describe a wireless network card

Describe a wireless network card

  Build a read-write property named validlastname

Create a read-write property named ValidLastName that stores a String value in the hidden variable mstrLastName. design the property using a Property Procedure.

  Examine what you believe to be a good backup

You work for a small consulting firm with a sterling reputation for high-quality work and outstanding technical aptitude. You've been assigned as SQL Server 2000 DBA for an e-commerce project based in coastal Florida.

  Write down an event handler that automatically assigns

design an ASP.NET project with Visual Studio.NET 2005. Add an aspx form to the application. Place a ListBox control, a TextBox control, a Label control, and a Button control on the form. Add at least three items to the ListBox control.

  The algorithms of the parallel and perspective projection

I have a java application that reads in a vertex list and face list. I also have code to write 2-D lines and ouput that image file. In my code I have the standard 3D default values defined for: PRP and VRP reference points, VPN and VUP vectors, an..

  What is the throughput

Measurements of the slotted ALOHA channel with an infinite number of users show that 10 percent of the slots are idle.

  Obtains the choice and show action based on that choice

Implements a switch: show the user three choices, obtains the choice and display an action based on that choice. One of the actions will include an if..else. Also include a default for incorrect choices.

  Write a c function named change that has a floating point

Call the function change from main function three times and print out the contents of the variables quarters, dimes, nickels, and pennies after each function return.

  How java programming knowledge benefits nonprogramming

How does information of programming concepts benefits individuals working in almost any IT position? Include at least one specific example of how java programming knowledge benefits nonprogramming working in IT?

  Chomsky normal form

Requesting assistance with the Theory of Computing.Construct a PDA that accepts L.

  Problem on troubleshooting dns records

Problem on Troubleshooting DNS Records

  What are all of ip addresses

What are all of IP addresses

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd