Write prolog code for the predicate in position

Assignment Help Basic Computer Science
Reference no: EM13776022

LEARNING OUTCOMES

Upon completion of this piece of coursework, a student will be able to: understand the functionality of Prolog predicates and express it in natural language; understand textual descriptions of predicates and design the corresponding Prolog programs; implement recursive predicates on lists consisting of complex terms; implement predicates exploiting the power of higher order built-in predicates; utilise procedural abstraction to decompose a complex predicate description into simpler ones and synthesise complex predicates by reusing already defined built-in or user-defined predicates; develop correct and well-documented programs on specific problems, and test them.

ASSESSMENT CRITERIA

Program correctness (code loads to Prolog with no warnings or error messages, correct use of recursion, procedural abstraction and built-ins, production of correct results for normal and boundary cases).

Proper code documentation and meaningful variable and predicate names.

Programming style (proper use of variable assignment, efficiency).

Explanation of the provided code and justification of design choices.

DETAILED DESCRIPTION

Description of ISOLA

This is a two-player game. You start with a 7´7 position board, which initially contains two pieces, one for each player. Both players (h for human and c for computer) flip a coin and whoever wins plays first. At each turn, a player can do two consecutive moves:

· Move one's own piece to a neighbouring position (horizontally, vertically or diagonally) that is empty (not crossed out).

· Remove any position from the board by crossing it out.

The looser is the player who cannot move its piece to a neighbouring position, i.e. the piece is isolated. There is no draw. The figure on the next page presents an instance of the game.

Aim of the Practical

The aim of this practical is to implement this game in Prolog. One player will be the human, and the other player will be the program, and in our case the computer always plays first. We are not concerned with the program being intelligent (at least not during this semester!) so the program will perform all its moves at random.

Questions

1. What does the predicate pp/1 do and how? Would it matter if the board elements were messed up (not in order)? Would it be possible to write a recursive predicate that does the same operation? Again, would the order of board elements matter?

2. Write Prolog code for the predicate in_position/3, which given a number and a list of items, returns the item that corresponds to the position indicated by the number. For example:

?- in_position (4, [a,b,c,d,e,f], X).

X = d

[10%]

3. As it stands now, next/4 finds the neighbouring positions vertically and horizontally. Can you complete it to make it work for diagonal neighbours?

4. As it stands now, computer always plays first. Can you modify the code, so that the human decides either who plays first or if the first player is to be chosen at random?

5. Write the definition of the predicate find_options/3, which given a position (X and Y coordinates) and a board, returns a list of all available neighbouring positions.

6. Consider the partial definition of select_one_to_move/3 predicate. It is implemented for player h but not for player c. Complete the definition so that player c selects in random an available position to move.

7. Write the definition of the predicate select_a_position_to_cross/3 predicate so that either player c or h selects an available position to cross out.

8. The board of the game could be represented by alternative notations. For example:

A list with 49 ordered places, i.e.:

board([-,-, ... -,-]).

A list of seven lists of seven items each, i.e.:

board([[-,-,-,-,-,-,-],...,[-,-,-,-,-,-,-]]).

A set of facts, i.e.

board((1,1),-).

board((2,1),-).

board((3,1),-).

...

board((7,7),-).

What would be the pros and cons of such representations, considering code complexity for list manipulation, ordering of list items, time and space efficiency, or any other factor you may think of?

9. This game could have variations in scale:

· It could be played in a smaller or bigger board, for example a 5´5 or a 11´11 board.

· There could be more than 2 players.

· It could be 3-dimensional

What changes, if any, would you perform in each of the above cases to the program in order to make it work?

Reference no: EM13776022

Questions Cloud

Describe what are the best arguments favoring each party : Brief the given case: Shahar v. Bowers, 114 F.3d 1097 (11th Cir. 1997), Facts of the Case (Discuss relevant facts; what happened? Why is this matter in court?) Contentions of the Parties (What are the best arguments favoring each party
Roles of corrections officers : Prepare a paper detailing the role of corrections officials. At a minimum, your paper should focus upon the corrections officers' place within the social roles of inmates as detailed in your text, and the role of corrections officers within jail a..
Describe options that organizations have for selecting proje : Describe options that organizations have for selecting projects that align with their mission and strategy and describe how each might work differently in the selection of IT projects
What was the legal issue presented to the court : Brief the given case: U.S. v. Thompson, 25 F 3d. 1558 (11th Cir. 1994), Issues Presented or Questions of Law: [What was the legal issue presented to the court?]
Write prolog code for the predicate in position : What does the predicate pp/1 do and how? Would it matter if the board elements were messed up (not in order)? Would it be possible to write a recursive predicate that does the same operation? Again, would the order of board elements matter?
Flushing stress hormones issue : What are the specific effects of physical exercise on managing and preventing stress
Problem related to the funding strategies : Prepare a two- to three-page paper on funding strategies for your start up business. In your paper:
Manufacture of a new chemical compound : Use the "goal seek" function within Excel to find the breakeven values for each of the following variables: the initial CAPEX, the working capital percentage of revenue growth, variable cost % of sales, and sale volume
Investigated relationship between iq and grade point average : Would the researchers reject or fail to reject the null hypothesis? Do the results provide sufficient evidence to support the alternative hypothesis?

Reviews

Write a Review

Basic Computer Science Questions & Answers

  Prepare a script to go along with the slide presentation

Prepare a script to go along with the slide presentation that could be read to provide an in-depth discussion of the topics highlighted on the slides. Research the topics above, using your textbook, information provided in class, and resources pro..

  Explain how versatility of excel affect application support

How does versatility of Excel affect application support? As its versatility, what assumptions should be made when diagnosing and troubleshooting Excel-based problems?

  In mips assembly language

In MIPS Assembly language

  Define function that takes an argument in name of a csv file

Define a function that takes an argument in the name of a CSV file. This file has a single row containing letter grades (A-F) separated by comma (hence CSV file). Your function should print the distribution of grades.

  What are the modes

What are the modes, the conceptual models of transfer, the advantages, and the disadvantages of pass-by-value, pass-by-result, pass-by-value result, and pass-by-reference parameter-passing methods?

  Input function to prompt the user to enter a square

In the script file, use the input function to prompt the user to enter a square 2-dimensional array. Use a loop to check that user's input is a square array and repeatedly ask the user to enter a square array until they enter a square array (you m..

  Create documentation for project that summarizes the process

Create documentation for this project that summarizes the process for using the entities and attributes for fleet truck maintenance. The Entities and Attributes for Fleet Truck Maintenance can be found in the Huffman Trucking Virtual Organization.

  Using java create a basic coin-flip guessing game

Using JAVA create a basic coin-flip guessing game. The game should prompt the player to choose heads or tails, flip a virtual coin and then display the results to the player.

  Determine the contents of the relocation

A program was initally loaded into memory starting at address 500. Determine the contents of the relocation register after the program is moved to address 200?

  What is projectitis

What is projectitis? How is it cured or its impact minimized?

  Create the data flow diagrams needed

The Chocolate Delights Candy Company needs to add the following functionality to its cash register: When a customer is checking out, the cash register needs to store the required data pertaining to each item the customer is buying.

  Translate infix mathematical expression into postfix express

Write a program in java to translate infix mathematical expression into postfix expression and a program to evaluate the posfix expression. There should be three separate progams. use stack data abstraction and class implementation.

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