Home

as a PDF

image

Contents

1. Progrann Demonstrating Prolog Usage Building a Simple Game By Wan Hussain Wan Ishak Abstract To demonstrate the use of Prolog and how programming in Prolog is easy and efficient this paper describe an implementation of the game booby trap a game similar to M inesweeper found on most personal computers with windows Introduction Prolog Programming in Logic isa well known programming language in the field of Artificial Intelligence Al Although Prolog has much in common with Lisp List Processing only Prolog has a built in automated reasoning system or inference engine Since its invention in 1972 by Alain Colmerauer and his colleagues at the U niversity of Aix M arsielle France there have been many versions of Prolog T hese include T urbo Prolog now supported by the Prolog D evelopment Center www pdc dk BinProlog 2 www binnetcorp com BinProlog SIC Stus Prolog Intelligent Systems Laboratory 1995 www sicsse g ctus and LamdaProlog 3 T here are also many other popular Prolog s such as Logic Programming Associates Prolog LPA www lpa co uk and AM ZI Prolog www amzi com D ozens of Prolog books and tutorials mention other lesser known Prologs Covington 4 one of many who tout Prologs versatility as a programming language points out how it can implement a variety of algorithms not just those for which it was specially designed Prolog consists of two main components facts and
2. not id Btt_ID assert id Btt_ID Red _Num_trap is Num_trap 1 create_trap Red_Num_trap Listing 2 Randomly creating the trap button PCAI ame DO AHI Apuna PEELE TEL Eee a SERRE RRR ERR RRR et N NE NEE NANE HAE eucesenaeen TR RRR ESE a Cloves p Cheat pearl a us Caneel iesi rakata Bakeries a a Beater RE T oe gid 362 i 4 ere choles T AOLA a 20 28 28 28 F wereatet Chooky 18 i button U 48 20 20 28 5 3 Figure 4 selects the button control from the toolbox and places it on the scratch window Ed Proceedings of the LPS 95 Postconference W orkshop on Vision for the Future of Logic Programming pp 83 94 Portland O regon References 1 Schildt H 1987 Advanced T urbo Prolog Version 1 1 Osborne M c Graw H ill California 6 Roth A and Spenser C 1993 The Benefits of Prolog Software D evelopment M iller Freeman Inc 2 Tarau P 1995 BinProlog 4 00 U ser Guide D ownload from citesee n nec com 2676 html on 18 Januari 2003 3 Brisset P and Ridoux O 1994 The Pare of an implementation of LambdaProlog Prolog M ali In Proceedings of the Workshop on Implementation of Logic Programming LPS 94 Ithaca N Y TheMIT Press N ovember 1994 D ownload from http citeseer nj nec com article brisset95 arch itecturehtm on 18 Januari 2003 Visual Prolog clear but yet extremely powerful object system for
3. E Grant P W Moseley L G and Spenser C 1998 A Flex based Expert System for Sewage T reatment W orks Support PC Al 12 4 35 38 11 Intelligent Systems Laboratory 1995 SIC Stus Prolog U ser s M anual D ownload from citeseer nj nec com 482697 html on 18 January 2003 12 Murphy T 1993 As you know love Prolog LPA 386 Prolog Al Expert M iller Freeman Inc 13 Spenser C 1997 LPA Prolog in Action PC Al 11 6 40 42 14 Taha Z 1988 Pemanduan Arah Robot M enggunakan Prolog Siri Seminar Sains Komputer II 18 1 18 7 Universiti Kebangsaan M alaysia Bangi 15 Westwood D 1999 LPA Win Prolog 3 6 T echnical Reference Logic Programming Association PC iN Wan Hussain Wan Ishak ison the Faculty of Information T echnology U niversti U tara Malaysia and can be reached at hussain uum edu my PCAI Appendix abolishing and declaring id 1 as a dynamic predicate abolish id 1 dynamic id 1 creating dialog create booby dialog _S1 dlg_ownedbyprolog ws_sysmenu ws caption _S2 ws_ child ws visible ws tabstop bs pushbutton _ 3 ws_child ws visibless right 4 ws child ws visiblews tabstop ws border es left es multilinees autohscroll es autovscroll wdcreate booby BOOBY TRAP GAME 398 212 362 271 S1 create buttons buttons 1 1 20 40 2 wccreate booby 1128 button CLOSE 270 210 70 30 S2 wccreate booby 10000 static Sco
4. 2 D elete an item from alist box example simplifies application wibxfnd 4 Find astring in a list box development W hile we illustrated how to develop a simple game program called a wlbxget 3 Get an item from a list box booby trap we also demonstrated some of Prologs capabilities and how users can a wlbxsel 3 Get or set selection in a list box a SEP types of applications By providing high Edit box class wedtsel 3 Get or set selection in an edit control window development environments such as LPA Po wedtfnd 6 Find atext string in an edit control window offers a Prolog system where areas such as games and intelligent interfaces are aa wedtlin 4 Get offsets alinein an edit control window directly now addressable by the Prolog i only developer N ext generation wedtpxy 4 Convert between li near offset and x y applications such as InF low IdeaP rocessor coordinates in edit windows and IntellX hint at someof the potential ee ae achievable using this powerful wedttxt 2 Get or set the text of the given edit window combination see www orgnet com www a Preoaring thetrap button Some buttons arerandomly selected and set as traps Click amp draw T he developer selects the button control from the toolbox and places it on the scratch window Figure 4 After the buttons are arranged side by side in rows and columns the edit control used for displaying the score is added T wo additional buttons are ad
5. Visual Prolog 4 Covington M A N ute D and Vellino A 1997 Prolog Programming in Depth Prentice The result is a very powerful and safe programming language which com bines some of the best features of H all N ew Jersey l Many programming paradigms in a qe consistent and elegant way Conway T and O Keefe R 1995 Logic Programming for the Real W orld In Donald A Smith PROLOG DEVELOPMENT 41 17 4 Imperative Programming The imperative programming style describes computation in terms of program state changes and statements that change the program state An example of a program state change would be selecting the reply button in an email program Before that the email program was displaying an email for you to read After the state change you now have a new email that is ready for you to edit not just read Imperative programming languages have primitives very similar to the CPU s machine instructions For example Branch statements memory assignment statements and add instructions Imperative programs consist of a series of commands for the computer to perform Almost all computer hardware is imperative designed to execute the native code of the computer machine code At this level the memory contents defined the state of the computer H igher level imperative style programming languages use variables to contain this state information Even though logic programming languages are t
6. ded to perform the N ev Gameand Close functions Handler Each button has its own unique ID Figure 3 The Booby T rap Game Screen PCAI languages programming by using existing easily use this language to develop many level access to the W indows GUI Prolog a com englisnH ome age deaP rocessor htm clicks a button the handler for the and www busness integrity com appropriate button is called with the IntealX html for more information unique id and the appropriate action is performed In this game only the N ew and Close buttons have e k a specific action and all of the others buttons p S e jj shared the same action depending on whether or not the button is a trap Buttons listed in id 1 World class World class multi platform extensible multi platform extensible are the trap buttons development environment Logic Programming tools while the others are not Source code debugging ISO Standard List 1 for Prolog logicbases running in other programs High performance for 24 7 and on remote Web server deployment servers Large logicbase support Code outlines and project cross references Integrates seamlessly with Java JSP NET C Team development tools VB C Delphi and more Automate the logical rules and relationships that run an organization Develop integrated logic base components Use professional development tools and methodologies Customize knowledge representat
7. display the score ki utton wit a a 4000 Defined the handler T he handler is nmuinbex stringlHasil H used to link the button with the wtext example 8002 H appropriate user defined action Figure 2 Creating and defining handler for the example window S o Fiex popular hybrid expert system toolkit creation and maintenance of the dialog code ge tributed agent toolkit Clicking the export button on the toolbox lets you view the Dat B powerfll data mining algorithm dialog code T he code appears in a dialog code window T he code ry and probat bilis mus be paste into a program file W in Prolog provides several built in predicates for GU I development T he D ialog Editor automatically creates some of these predicates such as wdcreate 7 and wccreate 8 T he window predicates are shown in T able 1 O ther predicates support the control classes T hese predicates are shown in T able 2 eChoice 0 of delivery environmant eeu j Modules inchude PCAI 39 17 4 Table 2 Built in Predicates for Preparing thetrap button T he program randomly selects 50 Control Classes buttons to be defined as a trap assert in king memory List 2 Control l ioe i Predicate Description Class i i Conclusion autore wanes Get or set the selection status of the given radio D ue to its vast capabilities Prolog or checkbox button can be a difficult language to master or even to teach H owever programming cia wlbxdel
8. g Editor plug in is a toolkit for easy development of GUIs and it allows easy 17 4 Massage Handling TT eee 2 After designing the interface and rena et placing the source code into the program ire Bed iter Trees ed T i i i TA 05a SS NEE NEAN EE E E EE EEEE E E Be a file the window handler is specified This ete oe a a aT o Serat h window handler catches any message generated by HEHN tbekribliet 3 the window and performs the specified Select ae ane action Therelation between a window and its handler can be defined using the window_handler W indow H andler predicate Figure 2 For example the window handler could be exp_handler H ence the relation between example window and exp_handler is defined as window_handler example exp_ handler 4 i A Booby Trap Game T he booby trap game is similar to OEE TE AE ACE pA M inesweeper except the rules and how it ee are plays are slightly different Figure 3 After the player selects a button the game returns a score If the button is a trap then the total score is reset to zero marian T he development of a program such Te Fonny 1000 msg button Result as this game involves the following steps t TAEA Saat WH Select and drag Create the buttons and number string Numberi H1 oe bis i edit control to
9. heoretically superior to imperative programming languages such as C C and Java there are two reasons why current logic programming languages such as Prolog are not as widely used for application development 1 Logic programming languages can be significantly slower than the equivalent program logic in an imperative language such as C Therefore application designers concerned with performance might not consider logic programming languages As computer speeds continue to increase and logic programming languages become even more efficient this reason could someday be eliminated 2 Current logic programming languages do not detect as many errors in programs as compilers for imperative programming languages which can reduce productivity Programmers must find more errors themselves usually during debug Languages such as Prolog do not require type casting which simplifies programming and increases flexibility H owever it also means the programmer is now responsible for finding many errors that a compiler with type checks would find 7 Luger G F 2002 Artificial Intelligence Structures and Strategies for C omplex Problem Solving Addison W esley U S 8 Bratko 1998 PROLOG Programming for Artificial Intelligence Addison W esley US 9 Bringsjord S 2002 Al Research to Al Business and Back Automatic Story Generation and Intelligent Document Production PC Al J anuary F eoruary 2002 pp 36 43 10 Dixon M L
10. ion and reasoning engines for individual application needs Apply advanced ontology concepts and develop semantic web applications d iL ows oa WWW aAmzZieCom 40 17 4 Run the dialog by typing start Create the dialog and defined the handler Start create the window create_booby_ dialog defining the handler window_handler booby booby_handler show the dialog show_dialog booby randomly choose the trap button create_trap 50 The handlers Called when user clicked the X on the upper right of the window booby _handler booby msg_close close Called when user clicked close button booby_handler booby 1128 msg_button close Called when user clicked new button booby _handler booby 1129 msg_button _ R r start Called when user clicked any button and the button is a trap booby_handler booby ID msg_button _ R id ID wtext booby ID F wtext booby 8000 0 l fail Called when user clicked any button booby_handler booby ID msg_button _ R wtext booby ID wtext booby 8000 X number_string Score X NewScore is Score 10 number_string NewScore X2 wtext booby 8000 X2 l fail Listing 1 Booby T rap H andler Create the trap button create_trap 0 stopping criteria Randomly select the trap button create_trap Num_trap 128 are the total number of buttons X is rand 128 Btt_ID is ip X
11. m solving with its declarative semantics and built in unification 38 T oday Prolog s have been enhanced with development environments and many integrated tools to simplify implementation This paper describes the implementation of asimple game program using LPA Win Prolog T his particular Prolog offers several tools for application development including a tool for developing Graphical U ser Interface GUI namely the LPA Dialog Editor T his tool lets you draw screens and generate and test the Prolog code in situ The LPA Dialog Editor is implemented entirely in LPA Win Prolog using the buit in predicates described in this article GUI Development The GUI an important element in system development must support an interactive interaction between the system and the user LPA s W in Prolog allows interactive dialog development utilizing a window dialog with GU I elements and control features along with a message handler to interpret the control messages W in Prolog offers two class types for developing dialogs window class and control class A window class supplies a Skeleton framework for developing dialogs T he W indow control class provides the means to embed control objects into windows with several control classes such as button edit list box combo box static scrollbar and graphics U sing the D ialog Editor plug in Figure 1 the user controls objects by click and drag on the scratch window T he Dialo
12. re 170 10 70 20 S3 wccreate booby 8000 edit 0 250 10 90 20 S4 wccreate booby 1129 button NEW 20 210 70 30 S2 create 128 buttons then stop buttons N um 128 Left T op Prop createbutton 128 Left T op Prop reset counter to 1 only 16 buttons in a row buttons 17 Id Left T op Prop N ewT op is T op 20 buttons 1 1d 20 N ewT op Prop create the buttons buttons N um d Left T op Prop createbutton Id Left T op Prop NewNum isNum 1 Newld isid 1 N ewLeft is Left 20 buttons N ewN um N ewld N ewLeft T op Prop create the button createbutton Id Left T op Prop wccreate booby Id button Left Top 20 20 Prop 42 17 4
13. rules T he facts PCAI describe relationships between objects whereas the rules define relationships between groups of facts Prolog is primarily based on three main concepts pattern matching automatic backtracking and tree based data structuring In the real world logic programming languages such as Prolog have not fulfilled their potential when compared to other conventional programming languages gt T his was not due as much to limitations in the language as to the ebb and flow of popular media and general computer hype According to Somogyi logic programming languages have theoretical advantages over conventional programming languages however they have not had the same impact on the computer industry Although this clam may betruein general in Al research many intelligent and knowledge based systems have been successfully developed and deployed using Prolog 4 M any of these applications would be much harder to develop in languages other than Prolog Furthermore Prolog is an expressive programming language which contrasts with conventional imperative languages see sidebar on imperative languages Prolog contains a number of advanced features including high level declarative programming automatic dynamic memory allocation and deallocation built in database functionality incremental compilation and meta programming In his book Luger ctates that Prolog has made many contributions to Al proble

Download Pdf Manuals

image

Related Search

Related Contents

GSS User Manual (v1.2.605)  Philips Blu-ray Disc/ DVD player BDP2180  Manual de instrucciones Balanza portátil  Toshiba F50 Laptop User Manual  Data Acquisition and Real Time DART User Manual  3043153 TOK Ölbrennwertkessel Montage- und    AEM31 MANUAL - Electrocomponents  OCTANE OPERATION MANUAL  Manual de instrucciones  

Copyright © All rights reserved.
Failed to retrieve file