⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 readme

📁 数据挖掘中de一个算法 hamster的实例
💻
📖 第 1 页 / 共 2 页
字号:
Hamster --- A Programming ContestThe hamster program is intended as some kind of contest for studentswho only recently learned to write programs. The current version ofthis program supports the programming languages C and SmallEiffel.(I am grateful to Ilona Bl"umel, who did most of the Eiffel programming.A Pascal version is currently being developed. If you want to use someother language: It is fairly simple to port the client program to otherprogramming languages, see below.)The current version is still a prototype. Do not expect too much ofit, there are some limitations. For example, the program is currentlyrestricted to a single hamster. In the future I plan to extend it toseveral hamsters in order to include parallel programming in thecontest (this may involve changing the control logic, though).Enjoy!Christian Borgelt------------------------------------------------------------------------Copying:This program is free software; you can redistribute it and/or modify itunder the terms of the GNU General Public License as published by theFree Software Foundation.This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See theGNU General Public License for more details.You should have received a copy of the GNU General Public License alongwith this program; if not, write to the Free Software Foundation, Inc.,59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.------------------------------------------------------------------------Idea:A hamster, who has not yet collected its winter store, is released intoa maze. In this maze a certain amount of corn is distributed in heapsof varying size. The task of the hamster is to collect as much cornas possible and to carry it back to its starting point. Of course,doing this, it has to try to minimize the distance it runs, in ordernot to use up the largest part of the collected corn as food right away.The problem to be solved is the following: The contestant is expectedto write program that controls the hamster while it is running aroundin the maze. To this end a limited set of functions is available, withwhich certain commands can be given to the hamster, like ``Turn left 90degrees!'', ``Move forward one field!'', ``Take three grains of corn!''etc. The order and number of these commands lies completely within theresponsibility of the contestant. He/She can do as he/she likes.How well a programs solved the task described above is computed on thebasis of the number of grains of corn collected, the length of the pathtravelled while collecting the corn, and the number of collisions withthe walls of the maze. These values are combined into a score, whichdetermines the ranking of the contest programs.------------------------------------------------------------------------The Programs and How to Build Them:The hamster program runs as two separate processes, called the server(the program that displays the window into which the maze is drawn) andthe client (the program that actually controls the hamster as it runsaround in the maze). The two processes communicate via an anonymouspipe. The names of the corresponding programs are as follows:             server         example C client   example Eiffel clientUnix         xhamster       hamster            ehamster (S.u.S.E. Linux)MS Windows   whamster.exe   hamster.exeThe name of the client program can be changed freely, since the serverprogram allows to select a program to be run as the client (via themenu entry `File > Select Hamster...'). However, the default is thename of the example C client program.The two programs are compiled from the following files:server, window version (Unix/X11 or MS Windows)  OS independent          Unix                    MS Windows  hamster/hamster.h       unix/menu.h  hamster/server.h        unix/menu.c  hamster/server.c        unix/fselect.h  hamster/maze.h          unix/fselect.c  hamster/maze.c          unix/sprite.h           windows/sprite.h                          unix/sprite.c           windows/sprite.c                                                  windows/whamster.rh                          unix/xhamster.rsc       windows/whamster.rc                          unix/xhamster.c         windows/whamster.c                          unix/excl.xbm                          unix/hamster.xbm        windows/hamster.bmp                                                  windows/mask.bmp                          unix/logo.xbm           windows/logo.bmpserver, command line version (Unix only)  unix/chamster.c         + OS independent filesexample C client (OS independent)  hamster/client.c  hamster/control.c  hamster/hamster.hexample Eiffel client (S.u.S.E. Linux SmallEiffel)  eiffel/client.e  eiffel/control.e  eiffel/hamster.eexample Pascal client (Gnu Pascal, under construction)  pascal/client.p  pascal/control.p  pascal/hamster.pTo compile the programs for Unix just do a 'make all' in the topdirectory (the directory that contains the makefile). If thecompilation fails, you may need to change the definitions of the`X11INC' and `X11LIB' macros in the makefile. I provided severaldefinitions for these two macros which I use on different machinesat the University of Magdeburg. The default setting is for S.u.S.E.Linux (tested under version 6.0). If the compilation was successful,you can start the hamster server with the `xh' script.The Eiffel version of the example client can be compiled underS.u.S.E. Linux by 'make ehamster' (provided SmallEiffel is installed).The Pascal version of the example client can be compiled under Unixby 'make phamster' (provided Gnu Pascal is installed).To compile the programs for MS Windows load the Microsoft C projectworkspace (whamster.mdp or whamster.dsw) into the Microsoft Cdevelopment environment and build both subprojects. If the compilationwas successful, you can start the hamster server by pressing Ctrl-F5or by starting `whamster.exe' from the `bin' directory.To test the programs, first initialize the maze: Select `Actions >Randomize Maze...' and simply press the `Ok' button. Then start theexample hamster control program with `Actions > Start Hamster'. Ifstarting the hamster control program fails, try to select the file`hamster' (Unix) or `hamster.exe' (MS Windows) from the `bin' directorywith `File > Select Hamster...' before starting the hamster. To testthe example Eiffel client, select the program 'ehamster' from the 'bin'directory; to test the example Pascal client, select 'phamster'.------------------------------------------------------------------------Porting to other Programming Languages:As already mentioned above, the hamster program runs as two separateprocesses. The sole task of the client program is to translate a callof a hamster function to a command that is written to stdout, to readthe reply of the server program from stdin and to pass the result backto the hamster control function. Thus, in principle, any programminglanguage can be used that allows us to compile a stand alone programthat writes to stdout and reads from stdin. The example C client programis compiled from the files `hamster.h', `hamster.c', and `client.c' inthe directory `hamster'. Hence, to port to a programming language otherthan C, it should be sufficient to translate these files to the desiredlanguage, provided there is a C compiler to compile the server program.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -