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

  How realistic is it for a company

Is it really essential for every software company to be CMM compliant or certified.

  How to use an external css file to style

give a Submit button for the form, and make up a name for the PHP script that would handle the replies on the Web server. At this stage, nothing will happen if the user clicks the Submit button. Just concentrate on the HTML5.

  Write down four logic functions that are true

Implement the four functions using a ROM.Assume that X consists of 3 bits, x2 x1 x0

  What is the least data transfer rate across the bus

What is the least data transfer rate across the bus

  Write down a program to request a person''s age

In order for exercise to be beneficial to cardiovascular system, heart rate (number of heart beats per minute) must exceed a value called the training heart rate.

  Make a structure that has one variable called value

design a structure that has one variable called value and one pointer to the list (making it a linked list). Prompt for 5 values from the keyboard as input and store them in the linked list.

  Information systems management

Describe at least three issues/problems with the Information Systems Management (ISM) in a named organization and explain at least three measures to address those issues. Explain the different measures that are effective? Why or why not?

  Implementing the java servlet

Write down the Java servlet which utilizes the doGet in order to return a markup document which provides your name, e-mail address, and mailing address along with the brief autobiography.

  What aim does a firewall play in an organization

How varios two routers be used to provide separation of a LAN from the outside world? Provide references.

  Make a use of microsoft project to create a project plan

make a Use of Microsoft Project to create a project plan

  Why is the object-oriented database model

Why is the object-oriented database model gaining acceptance for developing applications and managing  hypermedia databases at business websites.

  What are the pros and cons of a dhcp server

What are the pros and cons of having a DHCP server on each network segment, versus having some of the network segments receive their IP address and network configuration via a router using a DHCP relay agent? Consider how your answer depends on th..

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