Игровые программы на Прологе Лекция № 15. «Быки и коровы» play :- rnd(X1,X2,X3,X4), int2char(X1,C1), int2char(X2,C2), int2char(X3,C3), int2char(X4,C4),

Slides:



Advertisements
Similar presentations
#include void main() { float x = 1.66, y = 1.75; printf(%f%f,ceil(x), floor(y)); }
Advertisements

Etter/Ingber Arrays and Matrices. Etter/Ingber One-Dimensional Arrays 4 An array is an indexed data structure 4 All variables stored in an array are of.
Complex Integrity Constraints in SQL. Constraints over a Single Table Table Constraint: Create TABLE Sailors (sid INTEGER, sname CHAR(10), rating INTEGER,
For(int i = 1; i
Shuvendu Lahiri Kenneth McMillan Rahul Sharma Chris Hawblitzel Differential Assertion Checking.
Inheritance - Case Study TCP1201: 2013/2014. Case Study – Guessing Game Listed below is the code to play a guessing game using procedural programming.
Pointer to Structure. Structure variable can be access using pointers int a=10,*p; Here p  is an integer type pointer variable, p can hold the address.
Shuvendu Lahiri Kenneth McMillan Rahul Sharma Chris Hawblitzel Differential Assertion Checking.
Strings Input/Output scanf and printf sscanf and sprintf gets and puts.
Array_strcpy void array_strcpy(char dest[], char src[]) { int i = 0; while (src[i] != '\0') { dest[i] = src[i]; i++; } dest[i] = '\0'; }
1 DATA ABSTRACTION: USER DEFINED TYPES AND THE CLASS.
Lecture # 21 Chapter 6 Uptill 6.4. Type System A type system is a collection of rules for assigning type expressions to the various parts of the program.
Building Java Programs
GCSE Computing Working with numbers. Challenge ‘Crimson Mystical Mages’ is a fantasy role playing board game. You need to create an electronic program.
Topic 6A – The char Data Type. CISC 105 – Topic 6A Characters are Numbers The char data type is really just a small (8 bit) number. As such, each symbol.
Random (1) Random class contains a method to generate random numbers of integer and double type Note: before using Random class, you should add following.
CSE1301 Computer Programming: Lecture 27 Game Programming: Bingo.
Arrays Ethan Cerami New York University Today n Array Basics (Review) n Random Number Example n Passing Arrays to Functions n Strings.
1 Random numbers Random  completely unpredictable. No way to determine in advance what value will be chosen from a set of equally probable elements. Impossible.
Labs 6 and 7. Adding “Controls” to a Document Properties.
Section 3.6 BUILT-IN FUNCTIONS involving numbers & strings.
Recursion In general there are two approaches to writing repetitive algorithms. One uses loops(while, do while and for): the other uses recursion. Recursion.
Switch Statements Comparing Exact Values. 2 The Switch Statement The switch statement provides another way to decide which statement to execute next The.
Consecutive Numbers Algebra I.
Craps!. Example: A Game of Chance Craps simulator Rules – Roll two dice 7 or 11 on first throw, player wins 2, 3, or 12 on first throw, player loses 4,
Rational Expressions Section 0.5. Rational Expressions and domain restrictions Rational number- ratio of two integers with the denominator not equal to.
Multiplying and Dividing Integers When you MULTIPLY: Two positives equal a positive Two negatives equal a positive One positive & one negative equal.
CSE 201 – Elementary Computer Programming 1 Extra Exercises Source: Suggested but not selected midterm questions.
Characters. Character Data char data type – Represents one character – char literals indicated with ' '
 2008 Pearson Education, Inc. All rights reserved Case Study: Random Number Generation C++ Standard Library function rand – Introduces the element.
Switch Statements Comparing Exact Values. The Switch Statement: Syntax The switch statement provides another way to decide which statement to execute.
Java Basics.  To checkout, use: svn co scb07f12/UTORid  Before starting coding always use: svn update.
Introduction to Programming Lecture 11. ARRAYS They are special kind of data type They are special kind of data type They are like data structures in.
Iя heон sheона itОн, она, оно (не человек) weмы youты\вы theyони.
Welcome to the UK and the USA Выполнилa: Воронина М.А.
CHAPTER 6 ARRAYS IN C++ 2 nd Semester King Saud University College of Applied studies and Community Service CSC 1101 By: Fatimah Alakeel Edited.
Грамматический разбор английского предложения. Игры на Прологе
UNIT 11 Random Numbers.
CS 170 – INTRO TO SCIENTIFIC AND ENGINEERING PROGRAMMING.
Copyright © Texas Education Agency, Advanced Computer Programming Data Structures: Basics.
CSE202: Lecture 13The Ohio State University1 Function Scope.
Learn to subtract integers. Course Subtracting Integers.
How do we solve exponential and logarithmic equations and equalities?
CSC2100B Tutorial 6 Hashing Hao Ma Yi LIU Mar 4, 2004.
Random Numbers Random numbers are numbers generated whose sequence have no pattern Most calculators are able to generate random integers via a command.
1 Generating Random Numbers Textbook ch.6, pg
Introduction to programming in java Lecture 21 Arrays – Part 1.
Внимание! Так как файлы с поддержкой макроса невозможно загрузить, необходимо через режим разработчика вставьте этот код (Файл-Параметры-Настройка Ленты-
TUTORIAL 4 Visual Basic 6.0 Mr. Crone. Pseudocode Pseudocode is written language that is part-code part- English and helps a programmer to plan the layout.
BUS 599 Complete Class STR Check this A+ tutorial guideline at S-599-STR/BUS-599-Complete-Class- Guide For more classes.
Chapter 6 Arrays in C++ 2nd Semester King Saud University
Consecutive Numbers Algebra I.
Number guessing game Pick a random number between 1 and 10
CS 200 Branches Jim Williams, PhD.
The Random Class and its Methods
String Messy Details Unsigned vs signed.
Unit-2 Objects and Classes
Random Number Generation
Introduction to Programming
פחת ורווח הון סוגיות מיוחדות תהילה ששון עו"ד (רו"ח) ספטמבר 2015
1.) ) ) 62° a b c a b 49° c b a 58° 4.) ) ) 96° 44° b 85° 63° a c b a
Compiler Design Second Lecture.
Solving 1-Step Integer Equations
ECE 103 Engineering Programming Chapter 51 Random Numbers
Random functions.
Data Structures: Abstract Data Types (ADTs)
Essential Question: How can we determine if the model for a function should be discrete or continuous?
Revision.
Boolean in C++ CSCE 121.
P(1) = P(2) = P(3) = P(4) = P(5) = 0.166
Presentation transcript:

Игровые программы на Прологе Лекция № 15

«Быки и коровы» play :- rnd(X1,X2,X3,X4), int2char(X1,C1), int2char(X2,C2), int2char(X3,C3), int2char(X4,C4), WRITE("Ваши ходы: "),nl, move([C1,C2,C3,C4],1).

Загадывание компьютером числа rnd(X1,X2,X3,X4) :- rand(X1), rand(X2), NOT(find([X1],X2)), rand(X3), NOT(find([X1,X2],X3)), rand(X4), NOT(find([X1,X2,X3],X4)). rnd(X1,X2,X3,X4) :- rnd(X1,X2,X3,X4). rand(X) :- RANDOM(9,X). find([H|_],H). find([_|T],X):- find(T,X). int2char(I,C) :- str_int(S,I), str_char(S,C).

Подсчет попыток move(L,Moves) :- specmove(L,A,Moves), equal(L,A), nl, write(“Поздравляю!!! Вы угадали!"). move([C1,C2,C3,C4],10) :- NL, write("Количество попыток закончилось."),nl, write("Было загадано число "), write(C1), write(C2), write(C3), write(C4). move(L,Moves) :- NewMoves=Moves+1, move(L,NewMoves).

Проверка попытки specmove(L,[A1,A2,A3,A4],Moves) :- write(Moves), write(". "), readchar(A1), write(A1), readchar (A2), write(A2), readchar (A3), write(A3), readchar (A4), write(A4), check_bulls(L,[A1,A2,A3,A4],0), check_cows(L,[A1,A2,A3,A4],0), nl,!.

Проверка быков check_bulls([],_,Bulls):- write(Bulls), write(" : "). check_bulls([H1|T1],T2,Bulls) :- find(T2,H1), NewBulls=Bulls+1, check_bulls(T1,T2,NewBulls). check_bulls([_|T1],T2,Bulls) :- check_bulls(T1,T2,Bulls).

Проверка коров check_cows([],[],Cows) :- write(Cows). check_cows([H1|T1],[H1|T2],Cows):- NewCows=Cows+1, check_cows(T1,T2,NewCows). check_cows([_|T1],[_|T2],Cows):- check_cows(T1,T2,Cows).

Остальные разделы DOMAINS LIST=CHAR* PREDICATES nondeterm check_cows(LIST,LIST,INTEGER) nondeterm check_bulls(LIST,LIST,INTEGER) nondeterm rand(INTEGER) nondeterm rnd(INTEGER,INTEGER,INTEGER,INTEGER) nondeterm find(LIST,INTEGER) nondeterm int2char(INTEGER,CHAR) nondeterm specmove(LIST,LIST,INTEGER) nondeterm move(LIST,INTEGER) nondeterm play nondeterm equal(LIST,LIST) GOAL play.

Самостоятельное задание Модифицировать программу так, чтобы она работала еще во втором режиме «Машина - человек», т.е. чтобы человек загадывал число, а компьютер отгадывал его.