gotlobi.blogg.se

Netbeans vs jgrasp
Netbeans vs jgrasp








netbeans vs jgrasp

The static variable butPressed gives the recently pressed button and this information is used by the player Human class to fill a cell with ' x' or ' o' depending on the player turn Number. When the playTurn() method is called, it waits until the user presses one of the button from the 9x9 grid. This is the interface between the human and the game. It contains some necessary functions which a player should contain like playTurn(), notifyWin(), notifyLose(), etc. This is an abstract class and is extended by a player type. The bare at the right side of the jFrame shows three statuses: Number of games won by either player and Number of Draws. There is also a notification bar at the bottom of the jFrame. The text on top of these shows the block status. The display part contains a 9x9 grid of jButtons. The Classes, Human and Computer extend the Player class, hence an object of either class can be stored in pl1 and pl2 objects.

netbeans vs jgrasp

All the internal processing of the next Turn takes place by the Player object.

netbeans vs jgrasp

The method " checkWin()" checks win situation. The game alternately calls the playTurn methods of each player starting from player 1, updates the display and breaks the game whenever there is a win situation. There are two objects of type Player named " pl1" and " pl2". It is a 3x3 array initially filled with 0s.ġ stands for 'x' and 2 stands for 'o'. The state variable of type int stores the state of the game. The GUI of the game is made with netbeans Form maker. the method of finding the favourable state is explained later. The Game follows a very easy method of getting the most probable next chance. The model of the game can be summarized as follows. layerNum - int - Stores Layer Number (1-9).nodes - ArrayList - Stores reference to the Nodes in that Layer.nodeType - int - Stores whether this node is end node or not.comp - Computer - The Computer object this node belongs to.lNum - int - The layer number in which this node exists in the memory tree.n - int - Number of times this node is played.pref - int - Preference value of current Node.subNodes - String - Temporary storing ids of subNodes separated by ", ".sub_nodes - ArrayList - connections of this node to its subNodes.public void playTurn(int p,int turn) // overridden.layers - ArrayList - layers of memory tree.layerFiles - File - Layer Files from layer1.current - Node - Current Node of state tree.begin - Node - top element of the state tree.void playTurn(int pl,int turn) // overridden.public static int checkWin2(String x,String o).public static int checkWin(int turn,int st).w2 - int : Number of games won by Player1(O).w1 - int: Number of games won by Player1(X).butClicked - int: Button recently clicked by the user.pl2 - Player: Player 2 object (Computer / Human).pl1 - Player: Player 1 object (Computer / Human).state - int: Current state of the Game.Hope that after reading this post, you will be more interested in AI than before and will develop much better applications. The friendly language will help you easily understand the code. It is a simple demonstration of the power of AI. This project was originally developed by Mohd Akram.










Netbeans vs jgrasp