Conquer the medieval kingdom with CODERULER

zhaozj2021-02-16  77

Use this new, vivid graphics simulator to expand your Java programming skills

CODERULER is derived from 2004 ACM International Collegiate Programming Competition (see Resources), which is the latest fantasy game simulator challenge for IBM alphaworks. This game has a simple setting: You are the ruler of our medieval kingdom. Your farmers and knights depends on your wise strategic thinking, flexible strain ability and people's Java programming skills to survive, develop and prosper. As a game participant, your goal is to write Java code that simulates this ruler. The game simulator allows your rulers to deal with six opposing rulers (or built-in sample rulers) and determine the winner. This article guides you to rule your medieval kingdom in a simple way. It reveals the environment of the game, describes the rules, discusses the total strategy, and provides two, perfect, useful rulers that can be used immediately (or modify). Analog Environment CODERULER is a graphic, vivid analog gaming environment. As a medieval ruler, you must compete with other rulers to compete for land and forces. Your kingdom includes:

Farmers can occupy and cultivate land. Knights, you can fight and capture farmers, knights or occupation castles in other rulers. A castle that produces more knights and farmers. The more the land has, the faster they have their speed. Graphic Game World Game is expanded in the 2D world depicted by a kingdom. (Background topographic sketch is just as a wallpaper, it does not affect the gameplay or changing the progress of the game.) Figure 1 shows the in progress CODERULER game. Figure 1. Run CODERULER Figure 1 shows two confrontal rulers. The ruler - the planner behind the gaming object strategic activity - does not appear in the game world. Game objects (farmers, knights and castles) are colored dot marsh moved in the simulated world. Figure 2 shows the shape of the object and the direction thereof. Figure 2. Mobile mode of the CODERULER game object As can be seen from Figure 2, knights and farmers use the same mobile model. Each round, they move in one direction in eight possible directions. There is a associated number in each direction and this number will be used in Java encoding. Each number has a predefined constant (such as NW), which uses these constants in the code. The console score display can be seen in the right side of Figure 1. The name of the ruler in the current game and the name of the group they belong appear on the top of the console. These two numbers are the current score of the ruler (left) and the number of land roots owned by farmers. Figure 3 shows an example score display. Figure 3. The console score is displayed in Figure 3, and the ruler name is Simple Ruler from IBM DeveloperWorks. The current score of this ruler is 123, the kingdom of this ruler accounts for 774 land. You can click on the red x abort analog to the right above at any time. Land occupying the display list can be seen in the middle of Figure 1's status console. From Figure 4, it is easy to see that the land occupied by the blue ruler occupies more red rule. Figure 4. Land occupying an analog clock at the bottom of Figure 1 The bottom of the console is a clock. Figure 5 shows a close-up image. Figure 5. A CODERULER clock moves along the clock face of the clock. The game is over when the sun moves for a complete week. Every beating of the clock is a set of simulators. As a ruler, you decide the movement of each round of your own object. Fund rules Each ruler initially controls:

10 migrants 10 knights 1 castle

Creating new farmers and castle castles Creating farmers or knights depends on the number of land squares owned:

The rendezible land created a farmer or the number of rigories required for the knight or less than the 1251425012500101,000, more than 4,0004 in the game process, to:

Use farmers to occupy as much land as possible (and maintain a status). Use the Knight to capture the peasants as possible to make them no longer occupy the land. Use the Knight with the opponent's knight battle and capture as many knights as possible. This will weaken the opponent's unloading ability. Use the Knight attack to capture the castle of other rulers. The castle is a factory that produces knights and farmers, without them, can not create more farmers or knights. If there are multiple castles, the speed of creating a farmer or a knight can be faster than the opponent. See the sidebar to create new farmers and castles for creating speed. The strategy prevents your castle from falling. The captured game object has only a knight to capture the opponent's farmers, castle or knights. As long as you move it into the square of the farmers and the castle, they can capture them. To capture the knight of the opponent, you must first reduce its physical strength to 0. Every knight is the physical strength of 100, the opponent captures each attack, which will randomly lose a body value between 15 and 30. Perform a successfully captured knight get 20 physical units. The score program has to win the game, and the rulers you play must have the highest score at the end of the game. Pay attention to the benefits of the winner, or may not be. Table 1 shows the score scheme of the game. Table 1. Captified score schemes If ... then capture a farmer 4 to win a knight 6 points occupied a castle 15 points at the end of the game, the remaining objects, the occupied castle and the occupied land are added to the score In Table 2. Table 2. Score scheme for the remaining object

The remaining object scored a farmer 1-point Knight 2 points Castle 25 points, every 10 square 1 points game details each player writes the Java code of the simulated ruler. The game simulator makes your ruler with other rulers and decides to win. In the code, the movement of farmers, knights and castles must be coordinated. A set of API provides information about your objects and other competitive rulers. With this group of APIs, you can write code that achieves offense, defense, and even random strain strategies.

Seeing some of the planners behind CODERULER to learn about some ideas of the Coderuler engine, see some interviews of the creator Tim Deboer for Code Ruler. The game component CODERULER game requires Eclipse IDE to write, debug and test your ruler code. (See the Eclipse: integrated kingdom development environment.) CODERULER includes:

A interactive game simulator as a plugin for the Eclipse IDE. Can be used to write a document of the ruler's API. A set of movements, capture, and score rules. A local arena against a set of rulers against a set of sample rulers. A networking mechanism is used to submit the rulers to participate in the Open or set up their own tournaments. Simulation World Coordinate System This game is expanded in a simulation world containing 4608 squares - width 72 squares and 64 squares. Checkered is numbered by (x, y) coordinate system. The x-axis from left to right, Y axis from top to bottom. Figure 6 shows the layout of the CODERULER world. Location (0,0) in the upper left corner. Figure 6. CODERULER World Coordinate System CODERULER API and inheritance hierarchy need to understand the CODERULER API before command the game object. This API is a highly object-oriented and has a clear inheritance level. Understanding the hierarchy is the key to writing efficient CODERULER code. Figure 7 shows the inheritance hierarchy. Figure 7. CODERULER Inheritance Hierarchy Figure 7 The inheritance tree in Figure 7 is based on the Java interface. Each game object must implement it related interface: farmers must implement Ipeasant, knights must implement IKNIGHT. However, there is no need to write any of these classes because the CODERULER simulator uses a built-in implementation. As a ruler, the API provided by the interface is only required when information about the game object is needed. The IObject Interface IObject interface is the parent interface of all objects in the game. Each object indirectly implements IOBJECT. IObject extracts the common behavior of all objects: getRuler (): The ruler getx (), gety (): object's current location isalive (): This object is alive (ie, no capture) GetId (): The only ID (across all objects - knights, farmers, and castles) IObject parent interfaces There are two convenient methods. These methods are useful when designing strategies and can help you avoid using complex triangulation mathematics:

GetDirectionTo () calculates the most close proximity of the specified point in the figure. GetDistanceTo () calculates the distance of the specified point in the figure. The IPEASANT Interface Ipeasant interface does not add new behaviors to the IObject interface. The farmers can be moved with RULER's MOVE () method, which will change their position. You use farmers to occupy land. The automatic behavior of farmers is any land that occupies him. The hostile knight can capture farmers through mobile, not involving physical calculation. The ICASTLE interface ICASTLE interface is like an IPESANT interface, which does not add new behaviors to the IObject interface. The automatic behavior of a castle is to create more farmers or knights. Creating speed depends on the number of land owned. For creativity, see the sidebar to create new farmers and castles. The IKNIGHT interface IKNIGHT interface adds a method called getStregth () to the IOBJECT interface. A knight is captured at zero in its physical value. Loss knights can be avoided in a GetStregth () method with the Iknight interface in the strategy. For discussion on the corruption of the Knight, please refer to the capture game object in front of this article. The interface hierarchy in Figure 7 represents a game object that moves in the world during simulation. However, the ruler is not a game object and is not moved in the simulated world. The Iruler interface specifies the behavior of the ruler. The Iruler interface Iruler interface does not need - and not - inherits IObject. Figure 8 shows the inheritance hierarchy of the Iruler interface. Figure 8. Inheritance Level IRuler interface of the Iruler interface specifies the general behavior of all rulers. These include methods of acquiring information required to implement strategies:

GetPeasants () get all farmers under the name of the ruler. getknights () gets all the knights under the name of the ruler. Getcastles () gets all the castles under the name of the ruler. GetLandCount () gets the number of land roots owned by the ruler. getPoints () gets the score from the ruler currently won. GetRulerName () get the name of the ruler. GetSchoolName () gets the name of the group that creates the ruler. Ruler and MyRuler classes in order to enhance behavior specific to the game rules and help implement the Iruler interface, CODERULER provides the RULER class as shown in Figure 8. This class provides the default implementation of most Iruler methods. You have to write the contents of the MyRuler class, which must inherit the Ruler class. You don't need, or you should also modify the Ruler class. The workflow of the simulator is from the perspective of the CODERULER player, which has the following workflow:

Place the initial game object in the simulated world randomly selected Kingdom Location Call your INITIALIZE () method Each round call Your Ordersubjects () method getRulerName () and getSchoolName () methods should not contain strategic code. The simulator can call them at any time. Ruler provides a number of key ways to use in your own Myruler implementation:

Move () moves objects in the world. Capture () attacks the game object captured the opponent. Ruler also implemented several methods of changing the production model of the castle. By default, the castle continues to make farmers. However, you can use these methods to tell the castle to make a knight:

Createknights () tells the castle to make a knight. CreatePeasants () tells the castle to make peasants. Finally, one of the reasons for the Ruler class is to define abstract methods that must be implemented in their own MyRuler class. The analog engine calls these methods during execution. The only code that must be written is the implementation code of the methods listed in Table 3: Table 3. Methods in all MyRuler implementations

Method Description GetSchoolName () Returns a string with 25 or fewer characters, which identifies your group or community. (CODERULER is designed to compete between colleagues.) Determine the ruler during the game. For example, in Figure 1, the SCHOOL NAME of Simple Ruler is IBM DeveloperWorks. GetRulerName () returns a string with 25 or fewer characters, uniquely identifies the ruler. For example, one of the rulers in Figure 1 are named Simple Ruler. Initialize () When the ruler is placed in the game, the system calls this method. Perform all necessary initialization here. The initialization time is limited to one second. The computer that can be completed during initialization changes with the CPU speed and the Java VM used, but a second is sufficient for most code initialization tasks. Do not try to perform any work that relies on slow input / output. ORDERSUBJECTS () This is the core of CODERULER. This method is called once per round system. Need to use a strategy and tell your object what to do in this method. Eclipse: The integrated kingdom development environment needs to download and install Eclipse IDE (version 2.1 or update version) to run the CODERULER analog environment (see Resources). CODERULER is integrated into the Eclipse ID as a plug-in, thus utilizing Eclipse developers friendly features. Installing Eclipse and CODERULER To install Eclipse, unzip the publish document into a directory and run the Eclipse executable (Eclipse in * NIX, eclipse.exe in the Win32 system). JDK / JRE 1.4.2 or updated version is required to be installed. (Strongly recommended version 1.4.2, because CODERULER is developed and tested in this VM version.) After the Eclipse is installed, the CODERULER engine is downloaded (see Refigu). To install CODERULER, you need to extract the CODERULER release document to the / plugins directory. This creates a com.ibm.games directory in the Pugins directory. Start or restart Eclipse will be loaded. You can use CODERULER now. Creating your own CODERULER project requires a new project in Eclipse to use CODERULER. From the main menu, select Windows | Preferences. A dialog box will pop up as shown in Figure 9. Figure 9. Creating a new CODERULER project Select IBM Games in the list on the left, as shown in Figure 9. Then select CODERULER from the right GAME list. Finally, click OK to create a new CODERULER project with the template. You can write your own CODERULER now. In the IDE on the Options card bar, click the Java Perspective tab. Figure 10 shows this tab. Figure 10. Select Java Perspective to expand the SRC node in Eclipse, the default package shows the Myruler.java node, as shown in Figure 10. Double-click MyRuler.java node to open this file in the source code editor for editing. You must join your code here. The first ruler created by the first ruler is simple. It moves all farmers randomly. Listing 1 shows the code of this ruler, highlighting the added code with bold.

Timely completion of importance When writing a ruler code, you'll understand the time constraints encountered. For the initialize () method, it is limited to one second, which is quite a few times for all initialization code without output / output. If it takes more than one second, it will be interrupted and may only be completed. Each round in the game, the ordersubjects () method is limited to half seconds. ORDERSUBJECTS () The input parameters call you let you know how much time it is in the previous round. If the time limit is exceeded, it is not qualified to participate in the rest of the game. Listing 1. Simple Ruler of orderSubjects () implement import java.util.Random; ... protected Random rand = new Random (); public String getRulerName () {return "Simple Ruler";} public String getSchoolName () {return " IBM developerWorks ";} public void otsubjects (int lastmovetime) {ieSant [] peasants = getPeasants (); for (int i = 0; i

CODERULER "Don't do something" list smart strategy is critical to winning games, but CODERULER does not encourage the use of Java language features kidnap the game engine or win with other improper methods. The code should not:

Define constructor Use initial block Creating a thread Creating Process Writing Using JDBC Using Swing or AWT to create a GUI component Access network or other similar system functions use reflection and internal provision and pass through the simulator internal structure in the open competition and tournament Players who use these hacking techniques will be disqualified. A customized Java SecurityManager will capture most of this attempt. The battle of the first game should be tried in the first game, first save the latest edited ruler by clicking the save button in the toolbar or selecting the File> Save in the menu. Save and compile the code. Correct all types of typing errors or syntax errors before proceeding. You will notice 5 CODERULER-specific icon buttons, as shown in Figure 11. Figure 11. Integrated CODERULER button in the Eclipse toolbar illustrates the function of the button from left to right in Figure 11. Table 4. The function of the CODERULER button

Button Description Run Against Samples uses this button with the sample ruler against the sample to test your own rulers. Debug Against Samples uses this button with the sample ruler against the sample to test your own rulers. Run the ruler in debug mode, stop at the set break. After running the code, Run Against Other Teams will download the rulers of other groups. Use this button to fight against other groups of rulers to test their rulers. Debug Against Other Teams Run the ruler with the Ide's debug mode when the ruler with other groups tested their own rulers. Submit Code Submit the ruler. This also downloads a plus package of all rulers submitted by other groups. In the first trial, your first ruler will only confront the sample ruler. This means that you will only use the first button, that is, the button that is highlighted in Figure 11. When you click this button, CODERULER will start and load your ruler. You will have the opportunity to choose your opponent, as shown in Figure 12. Figure 12. Select the game opponent to add a Do Not Nothing Ruler. Start game and observe how farmers move randomly and occupy land. This game can be easily won. Then, try the Random Ruler. The behavior of this ruler is almost the same as your rulers. The average land is substantially the same. If you confront any other sample ruler, the Simple Ruler you created is likely to lose. Most other sample rulers will actively capture your objects. Attacks should now be added to this Simple Ruler. Creating an Offense Rule Listing 2 shows the modified ruler code, highlighting the added code. Listing 2. Amended Simple Ruler implementation, it actively

import com.ibm.ruler *;. import java.awt.Point; import java.util.Random; import java.util.Vector; public class MyRuler extends Ruler {public String getRulerName () {return "Simple Ruler";} public String getSchoolName () {return "IBM developerWorks";} public void initialize () {} protected Random rand = new Random (); protected Vector enemies = new Vector (); public void orderSubjects (int lastMoveTime) {IPeasant [] peasants = getPeasants (); IkNight [] knights = getknights (); for (int i = 0; i

= knight.gety ()) {move (knight, rand.nextint (8) 1); return;} // capture anything there is in our way ibject obj = world.getObject (np.x, np.y) ; if ((OBJ! = null) && (obj.getruler ()! = this))))))) Capture (knight, dir); Else Move (knight, dir);}} @ 万 能 万 w 对 对 对 在 编 编 大 大Previously, to ensure the same time to study the document of the World object. This object contains many static methods, which will be useful for implementing your strategy. For example, you can use Getlandowner () to find the land of a lattice, identify the game objects at a specific location with getObject (), getotherknights (), getotherknights (), gethartrastles (), getoTherrRules () to find the enemy. You will experience the role of the code that highlights the code in the list 2. The code with red highlights set a vector containing all living enemy game objects in the world. Note This information is obtained using the World.getotherpeasants ()). Use blue highlighting code to traverse all of your knights and move them towards alive game objects. It also captures the hostile objects that may encounter. It uses the MoveandCapture () method to move and capture. MoveandCapture () methods make specific knights toward specific enemy objects. It uses the getPositionAfterMove () method of the World object to determine if the knight caught in a dilemma. If so, random movement. It also uses the GetObject () method of the World object and captures all enemy objects that may be on its road. Try to use this new Simple Ruler to fight against some sample rulers. You will see that it can have a good progress on many of them. Of course, there is a big improvement. As an exercise, you can try this to modify the code:

Command Your Castle generates a knight when the number of knights is lowered. More effectively specify the goal for the knight. Make farmers more effectively occupy the land. Make farmers to avoid capture. When the number of farmers and knights becomes low, it is converted to a defensive survival strategy. Conclusion by you: From the easiest way to test-based mechanical rulers to the most complex, CODERULERS is provided by the statistical game theoretical model. CODERULERS provides all possibilities. Just like in the real world, the most complex strategy and complex coding may not guarantee victory. In fact, some champion rulers use the easiest, but the most exciting guerrillas. If the strategic design and Java development are your favorite, then you should try CODERULER. Reference

转载请注明原文地址:https://www.9cbs.com/read-16781.html

New Post(0)