Search Results

Search found 18 results on 1 pages for 'cloneable'.

Page 1/1 | 1 

  • Question about the Cloneable interface and the exception that should be thrown

    - by Nazgulled
    Hi, The Java documentation says: A class implements the Cloneable interface to indicate to the Object.clone() method that it is legal for that method to make a field-for-field copy of instances of that class. Invoking Object's clone method on an instance that does not implement the Cloneable interface results in the exception CloneNotSupportedException being thrown. By convention, classes that implement this interface should override Object.clone (which is protected) with a public method. See Object.clone() for details on overriding this method. Note that this interface does not contain the clone method. Therefore, it is not possible to clone an object merely by virtue of the fact that it implements this interface. Even if the clone method is invoked reflectively, there is no guarantee that it will succeed. And I have this UserProfile class: public class UserProfile implements Cloneable { private String name; private int ssn; private String address; public UserProfile(String name, int ssn, String address) { this.name = name; this.ssn = ssn; this.address = address; } public UserProfile(UserProfile user) { this.name = user.getName(); this.ssn = user.getSSN(); this.address = user.getAddress(); } // get methods here... @Override public UserProfile clone() { return new UserProfile(this); } } And for testing porpuses, I do this in main(): UserProfile up1 = new UserProfile("User", 123, "Street"); UserProfile up2 = up1.clone(); So far, no problems compiling/running. Now, per my understanding of the documentation, removing implements Cloneable from the UserProfile class should throw an exception in up1.clone() call, but it doesn't. I've read around here that the Cloneable interface is broken but I don't really know what that means. Am I missing something?

    Read the article

  • Question about cloning in Java

    - by devoured elysium
    In Effective Java, the author states that: If a class implements Cloneable, Object's clone method returns a field-by-field copy of the object; otherwise it throws CloneNotSupportedException. What I'd like to know is what he means with field-by-field copy. Does it mean that if the class has X bytes in memory, it will just copy that piece of memory? If yes, then can I assume all value types of the original class will be copied to the new object? class Point { private int x; private int y; @Override public Point clone() { return (Point)super.clone(); } } If what Object.clone() does is a field by field copy of the Point class, I'd say that I wouldn't need to explicitly copy fields x and y, being that the code shown above will be more than enough to make a clone of the Point class. That is, the following bit of code is redundant: @Override public Point clone() { Point newObj = (Point)super.clone(); newObj.x = this.x; //redundant newObj.y = this.y; //redundant } Am I right? I know references of the cloned object will point automatically to where the original object's references pointed to, I'm just not sure what happens specifically with value types. If anyone could state clearly what Object.clone()'s algorithm specification is (in easy language) that'd be great. Thanks

    Read the article

  • What's a good way to programmatically manage a cloneable entity?

    - by bobobobo
    Say you have missiles or rockets that a player can fire. What's a good way to programmatically manage the cloning of a base rocket, for example? I can think of 2 ways to do it: Player has a currently selected weapon (which is an int) When player shoots, the selectedWeapon member is looked at, and the correct instance of rocket is created (with some base parameters) Or Player has a currently selected weapon (which is a pointer, to a "base instance" of the rocket object) When player shoots, the base instance rocket is cloned, transformed, and shot into the game world

    Read the article

  • Implementing clone on a LinkedList

    - by devoured elysium
    I am trying to implement a clone() method on a DoubleLinkedList. Now, the problem is that implementing it by "the convention" is a lot more troublesome than just creating a new DoubleLinkedList and filling it with all the elements of my current DoubleLinkedList. Is there any inconvenient I am not seeing when doing that? Here is my current approach: @Override public DoubleLinkedList<T> clone() { DoubleLinkedList<T> dll = new DoubleLinkedList<T>(); for (T element : dll) { dll.add(element); } return dll; } Here is what it would be by the convention: @Override public DoubleLinkedList<T> clone() { try { DoubleLinkedList<T> dll = (DoubleLinkedList<T>)super.clone(); //kinda complex code to copy elements return dll; } catch (CloneNotSupportedException e) { throw new InternalError(e.toString()); } }

    Read the article

  • Implementing Clonable in Java

    - by Artium
    In which cases should I use this way: public A clone() throws CloneNotSupportedException { A clone = (A)super.clone(); clone.x= this.x; return clone; } And in which cases should I use that way: public ShiftedStack clone() throws CloneNotSupportedException { return new A(this.x); } What should I do if x is final and I want to use the first way? Regarding the first way, I understand it like this: we clone the super class and up-cast it, leading to some members uninitialized. After this initialize these members. Is my understanding correct? Thank you.

    Read the article

  • Standard Interfaces

    - by Amir Rachum
    I've used Java for some time and I keep hearing about interfaces such as Cloneable, Iterable and other X-ables. I was wondering if there is a list somewhere of all of these and more importantly - which ones do you regularly use day-to-day? For example, I've read that Cloneable is considered badly written and isn't widely used.

    Read the article

  • Abstract class + Inheritance vs Interface

    - by RealityDysfunction
    Hello fellow programmers, I am reading a book on C# and the author is comparing Abstract classes and Interfaces. He claims that if you have the following "abstract class:" abstract class CloneableType { public abstract object Clone(); } Then you cannot do this: public class MiniVan : Car, CloneableType {} This, I understand. However he claims that because of this inability to do multiple inheritance that you should use an interface for CloneableType, like so: public interface ICloneable { object Clone(); } My question is, isn't this somewhat misleading, because you can create an abstract class which is "above" class Car with the method Clone, then have Car inherit that class and then Minivan will inherit Car with all these methods, CloneAble class - Car class - Minivan Class. What do you think? Thanks.

    Read the article

  • Useful Extension Method for ICloneable

    - by DesigningCode
    In the past, I’ve had to put a type specific clone in each cloneable class, but with extension methods you can write a generic T specific clone class Program { static void Main(string[] args) { var b = new Blah() {X = 1, Y = 2}; var bb = b.Clone(); Console.WriteLine(string.Format("{0} {1}", bb.X, bb.Y)); } } public class Blah : ICloneable { public int X; public int Y; object ICloneable.Clone() { return MemberwiseClone(); } } public static class CloneExtension { public static T Clone<T>(this T o) where T : ICloneable { return (T)o.Clone(); } }

    Read the article

  • What's My Problem? What's Your Problem?

    - by Jacek Ziabicki
    Software installers are not made for building demo environments. I can say this much after 12 years (on and off) of supporting my fellow sales consultants with environments for software demonstrations. When we release software, we include installation programs and procedures that are designed for use by our clients – to build a production environment and a limited number of testing, training and development environments. Different Objectives Your priorities when building an environment for client use vs. building a demo environment are very different. In a production environment, security, stability, and performance concerns are paramount. These environments are built on a specific server and rarely, if ever, moved to a different server or different network address. There is typically just one application running on a particular server (physical or virtual). Once built, the environment will be used for months or years at a time. Because of security considerations, the installation program wants to make these environments very specific to the organization using the software and the use case, encoding a fully qualified name of the server, or even the IP address on the network, in the configuration. So you either go through the installation procedure for each environment, or learn how to clone and reconfigure the software as a separate instance to build all your non-production environments. This may not matter much if the installation is as simple as clicking on the Setup program. But for enterprise applications, you have a number of configuration settings that you need to get just right – so whether you are installing from scratch or reconfiguring an existing installation, this requires both time and expertise in the particular piece of software. If you need a setup of several applications that are integrated to talk to one another, it is a whole new level of complexity. Now you need the expertise in all of the applications involved (plus the supporting technology products), and in addition to making each application work, you also have to configure the integration endpoints. Each application needs the URLs and credentials to call the integration layer, and the integration must be able to call each application. Then you have to make sure that each app has the right data so a business process initiated in one application can continue in the next. And, you will need to check that each application has the correct version and patch level for the integration to work. When building demo environments, your #1 concern is agility. If you can get away with a small number of long-running environments, you are lucky. More likely, you may get a request for a dedicated environment for a demonstration that is two weeks away: how quickly can you make this available so we still have the time to build the client-specific data? We are running a hands-on workshop next month, and we’ll need 15 instances of application X environment so each student can have a separate server for the exercises. We cannot connect to our data center from the client site, the client’s security policy won’t allow our VPN to go through – so we need a portable environment that we can bring with us. Our consultants need to be able to work at the hotel, airport, and the airplane, so we really want an environment that can run on a laptop. The client will need two playpen environments running in the cloud, accessible from their network, for a series of workshops that start two weeks from now. We have seen all of these scenarios and more. Here you would be much better served by a generic installation that would be easy to clone. Welcome to the Wonder Machine The reason I started this blog is to share a particular design of a demo environment, a special way to install software, that can address the above requirements, even for integrated setups. This design was created by a team at Oracle Utilities Global Business Unit, and we are using this setup for most of our demo environments. In a bout of modesty we called it the Wonder Machine. Over the next few posts – think of it as a novel in parts – I will tell you about the big idea, how it was implemented and what you can do with it. After we have laid down the groundwork, I would like to share some tips and tricks for users of our Wonder Machine implementation, as well as things I am learning about building portable, cloneable environments. The Wonder Machine is by no means a closed specification, it is under active development! I am hoping this blog will be of interest to two groups of readers – the users of the Wonder Machine we have built at Oracle Utilities, who want to get the most out of their demo environments and be able to reconfigure it to their needs – and to people who need to build environments for demonstration, testing, training, development and would like to make them cloneable and portable to maximize the reuse of their effort. Surely we are not the only ones facing this problem? If you can think of a better way to solve it, or if you can help us improve on our concept, I will appreciate your comments!

    Read the article

  • How to Clone Control in WPF ?

    - by Homam
    Hi, I want to clone a WPF Control (XamDataGrid) I know these ways: Clone Problem: Control is not Cloneable Serialize & Deserialize in binary format Problem: Control is not serializable Serialize as XML Problem: control contains images and Images are not serializable in xml serialization Do you have any valid workarounds ?

    Read the article

  • How do I set values for a class without using any setter methods?

    - by fari
    Please can anyone help me public class KalaGameState implements Cloneable { // your code goes here public KalaGameState(int startingStones) throws InvalidStartingStonesException { // your code goes here } public int getTurn() { // your code goes here } public int getKala(int playerNum) throws IllegalPlayerNumException { // your code goes here } public int getNumStones(int sidePitNum) throws IllegalSidePitNumException { // your code goes here } public int getNumStones(int playerNum, int sidePitNum) throws IllegalPlayerNumException, IllegalSidePitNumException { // your code goes here } public int getScore(int playerNum) throws IllegalPlayerNumException { // your code goes here } private int getSidePitArrayIndex(int sidePitNum) throws IllegalSidePitNumException { // your code goes here } public boolean gameOver() { // your code goes here } public void makeMove(int sidePitNum) throws IllegalSidePitNumException, IllegalMoveException { // your code goes here } }

    Read the article

  • preverification error in netbeans and eclipse while including j2ssh maverick

    - by user568651
    problem-- Preverification errors: Error preverifying class com.maverick.ssh.components.ComponentFactory java/lang/NoClassDefFoundError: java/lang/Cloneable j2ssh Unknown Java Problem this error comes while j2ssh is added as a library in my application. console-- Uncaught exception: java.lang.NoClassDefFoundError: com/maverick/ssh/LicenseManager - mobilessh.MobileSSH.run(), bci=2 - java.lang.Thread.run(), bci=11 this error shows both in eclipse and netbeans ide 6.9.1 jdk 1.6 installed.. wtk 3.0 and 2.5.2.

    Read the article

  • Deep clone utility recomendation

    - by Supowski
    Is there any utility for deep cloning for java collections: Arrays Lists Maps NOTE: prefer some solution without usage of serialization, but with use of Object.clone() method. I can be sure that my custom object will implement clone() method and will use only java-standard classes that are cloneable...

    Read the article

  • DRYing out implementation of ICloneable in several classes

    - by Sarah Vessels
    I have several different classes that I want to be cloneable: GenericRow, GenericRows, ParticularRow, and ParticularRows. There is the following class hierarchy: GenericRow is the parent of ParticularRow, and GenericRows is the parent of ParticularRows. Each class implements ICloneable because I want to be able to create deep copies of instances of each. I find myself writing the exact same code for Clone() in each class: object ICloneable.Clone() { object clone; using (var stream = new MemoryStream()) { var formatter = new BinaryFormatter(); // Serialize this object formatter.Serialize(stream, this); stream.Position = 0; // Deserialize to another object clone = formatter.Deserialize(stream); } return clone; } I then provide a convenience wrapper method, for example in GenericRows: public GenericRows Clone() { return (GenericRows)((ICloneable)this).Clone(); } I am fine with the convenience wrapper methods looking about the same in each class because it's very little code and it does differ from class to class by return type, cast, etc. However, ICloneable.Clone() is identical in all four classes. Can I abstract this somehow so it is only defined in one place? My concern was that if I made some utility class/object extension method, it would not correctly make a deep copy of the particular instance I want copied. Is this a good idea anyway?

    Read the article

  • Understanding SingleTableEntityPersister n QueryLoader

    - by Iapilgrim
    Hi, I have the Hibernate model @Cache(usage = CacheConcurrencyStrategy.NONE, region = SitesConstants.CACHE_REGION) public class Node extends StatefulEntity implements Inheritable, Cloneable { private Node _parent; private List<Node> _childNodes; .. } @Cache(usage = CacheConcurrencyStrategy.NONE, region = SitesConstants.CACHE_REGION) public class Page extends Node implements Defaultable, Securable { private RootZone _rootZone; ...... @OneToOne(fetch = FetchType.LAZY) @JoinColumn(name = "root_zone_id", insertable = false, updatable = false) public RootZone getRootZone() { return _rootZone; } public void setRootZone(RootZone rootZone) { if (rootZone != null) { rootZone.setPageId(this.getId()); _rootZone = rootZone; } } I want to get all pages ( call getSiteTree), so I using this query String hpql = "SELECT n FROM Node n "; See the trace I find Page.setRootZone(RootZone) line: 155 NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not available [native method] NativeMethodAccessorImpl.invoke(Object, Object[]) line: 39 DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: 25 Method.invoke(Object, Object...) line: 597 BasicPropertyAccessor$BasicSetter.set(Object, Object, SessionFactoryImplementor) line: 66 PojoEntityTuplizer(AbstractEntityTuplizer).setPropertyValues(Object, Object[]) line: 352 PojoEntityTuplizer.setPropertyValues(Object, Object[]) line: 232 SingleTableEntityPersister(AbstractEntityPersister).setPropertyValues(Object, Object[], EntityMode) line: 3580 TwoPhaseLoad.initializeEntity(Object, boolean, SessionImplementor, PreLoadEvent, PostLoadEvent) line: 152 QueryLoader(Loader).initializeEntitiesAndCollections(List, Object, SessionImplementor, boolean) line: 877 QueryLoader(Loader).doQuery(SessionImplementor, QueryParameters, boolean) line: 752 QueryLoader(Loader).doQueryAndInitializeNonLazyCollections(SessionImplementor, QueryParameters, boolean) line: 259 QueryLoader(Loader).doList(SessionImplementor, QueryParameters) line: 2232 QueryLoader(Loader).listIgnoreQueryCache(SessionImplementor, QueryParameters) line: 2129 QueryLoader(Loader).list(SessionImplementor, QueryParameters, Set, Type[]) line: 2124 QueryLoader.list(SessionImplementor, QueryParameters) line: 401 QueryTranslatorImpl.list(SessionImplementor, QueryParameters) line: 363 HQLQueryPlan.performList(QueryParameters, SessionImplementor) line: 196 SessionImpl.list(String, QueryParameters) line: 1149 QueryImpl.list() line: 102 QueryImpl.getResultList() line: 67 NodeDaoImpl.getSiteTree(long) line: 358 PageNodeServiceImpl.getSiteTree(long) line: 797 NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not available [native method] NativeMethodAccessorImpl.invoke(Object, Object[]) line: 39 DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: 25 Method.invoke(Object, Object...) line: 597 AopUtils.invokeJoinpointUsingReflection(Object, Method, Object[]) line: 307 JdkDynamicAopProxy.invoke(Object, Method, Object[]) line: 198 $Proxy100.getSiteTree(long) line: not available the calling setRootZone in Page makes Hibernate issue a hit to database. I don't want this. So my question is + Why query String hpql = "SELECT n FROM Node n "; issues un-expected trace logs like above. Why the query String hpql = "SELECT n.nodename FROM Node n " not? What is the mechanism behind? Note: Im using hibernate caching level 2. In case I don't want to see that trace logs. I mean I just get Node data only. How to do ? Thanks for your help. Sorry for my bad english :( Van

    Read the article

  • Original object is also changed when values of cloned object are changed.

    - by fari
    I am trying to use clone but the original object is also changed when values of cloned object are changed. As you can see KalaGameState does not use any objects so a shallow copy should work. /** * This class represents the current state of a Kala game, including * which player's turn it is along with the state of the board; i.e. the * numbers of stones in each side pit, and each player's 'kala'). */ public class KalaGameState implements Cloneable { // your code goes here private int turn; private int[] sidePit; private boolean game; public Object clone() { try { return super.clone(); } catch (CloneNotSupportedException e) { // This should never happen throw new InternalError(e.toString()); } } /** * Constructs a new GameState with a specified number of stones in each * player's side pits. * @param startingStones the number of starting stones in each side pit. * @throws InvalidStartingStonesException if startingStones not in the range 1-10. */ public KalaGameState(int startingStones) throws InvalidStartingStonesException { game=true; turn=0; sidePit=new int[14]; for (int i=0; i <= 13 ; i++) { sidePit[i] = startingStones; } sidePit[6] =0; sidePit[13] =0; // your code goes here } /** * Returns the ID of the player whose turn it is. * @return A value of 0 = Player A, 1 = Player B. */ public int getTurn() { return turn; // your code goes here } /** * Returns the current kala for a specified player. * @param playerNum A value of 0 for Player A, 1 for Player B. * @throws IllegalPlayerNumException if the playerNum parameter * is not 0 or 1. */ public int getKala(int playerNum) throws IllegalPlayerNumException { if(playerNum!=0 || playerNum!=1) throw new IllegalPlayerNumException(playerNum); if(playerNum==0) return sidePit[6]; else return sidePit[13]; // your code goes here } /** * Returns the current number of stones in the specified pit for * the player whose turn it is. * @param sidePitNum the side pit being queried in the range 1-6. * @throws IllegalSidePitNumException if the sidePitNum parameter. * is not in the range 1-6. */ public int getNumStones(int sidePitNum) throws IllegalSidePitNumException { if(turn==0) { if(sidePitNum>6 ) throw new IllegalSidePitNumException(sidePitNum); } else if(sidePitNum>12) throw new IllegalSidePitNumException(sidePitNum); if(turn==0) return sidePit[sidePitNum]; else return sidePit[sidePitNum+6]; // your code goes here } /** * Returns the current number of stones in the specified pit for a specified player. * @param playerNum the player whose kala is sought. (0 = Player A, 1 = Player B). * @param sidePitNum the side pit being queried (in the range 1-6). * @throws IllegalPlayerNumException if the playerNum parameter is not 0 or 1. * @throws IllegalSidePitNumException if the sidePitNum parameter is not in the * range 1-6. */ public int getNumStones(int playerNum, int sidePitNum) throws IllegalPlayerNumException, IllegalSidePitNumException { /*if(playerNum>2) throw new IllegalPlayerNumException(playerNum); if(turn==0) { if(sidePitNum>6 ) throw new IllegalSidePitNumException(sidePitNum); } else if(sidePitNum>12) throw new IllegalSidePitNumException(sidePitNum); */ if(playerNum==0) return sidePit[sidePitNum]; else if(playerNum==1) return sidePit[sidePitNum+7]; else return sidePit[sidePitNum]; } /** * Returns the current score for a specified player - the player's * kala plus the number of stones in each of their side pits. * @param playerNum the player whose kala is sought. (0 = Player A, 1 = Player B). * @throws IllegalPlayerNumException if the playerNum parameter is not 0 or 1. */ public int getScore(int playerNum) throws IllegalPlayerNumException { if(playerNum>1) throw new IllegalPlayerNumException(playerNum); int score=0; if(playerNum==0) { for(int i=0;i<=5;i++) score=score+sidePit[i]; score=score+sidePit[6]; } else { for(int i=7;i<=12;i++) score=score+sidePit[i]; score=score+sidePit[13]; } // your code goes here return score; } private int getSidePitArrayIndex(int sidePitNum) throws IllegalSidePitNumException { if(turn==0) { if(sidePitNum>6 ) throw new IllegalSidePitNumException(sidePitNum); } else if(sidePitNum>12) throw new IllegalSidePitNumException(sidePitNum); if(turn==0) { return sidePitNum--; } else { return sidePitNum+6; } } public boolean gameOver() { int stone=0; if(turn==0) for(int i=0;i<=5;i++) stone=stone+getNumStones(i); else for(int i=7;i<=12;i++) stone=stone+getNumStones(i-7); if (stone==0) game=false; return game; } /** * Makes a move for the player whose turn it is. * @param sidePitNum the side pit being queried (should be in the range 1-6) * @throws IllegalSidePitNumException if the sidePitNum parameter is not in the range 1-6. * @throws IllegalMoveException if the side pit is empty and has no stones in it. */ public void makeMove(int sidePitNum) throws IllegalSidePitNumException, IllegalMoveException { if(turn==0) { if(sidePitNum>6 ) throw new IllegalSidePitNumException(sidePitNum); } else if(sidePitNum>12) throw new IllegalSidePitNumException(sidePitNum); /* if(turn==0) { if(sidePit[sidePitNum-1]==0) throw new IllegalMoveException(sidePitNum); } else { if(sidePit[sidePitNum-1+7]==0) throw new IllegalMoveException(sidePitNum); } */ sidePitNum--; int temp=sidePitNum; int pitNum=sidePitNum+1; int stones=getNumStones(turn,sidePitNum); if(turn==0) sidePit[sidePitNum]=0; else { sidePitNum=sidePitNum+7; sidePit[sidePitNum]=0; pitNum=pitNum+7; } while(stones!=0) { if(turn==0) { sidePit[pitNum]=sidePit[pitNum]+1; stones--; pitNum++; if(pitNum==13) pitNum=0; } else { sidePit[pitNum]=sidePit[pitNum]+1; stones--; pitNum++; if(pitNum==6) pitNum=7; else if(pitNum==14) pitNum=0; } } boolean res=anotherTurn(pitNum); if(!res){ capture(pitNum,temp); if(turn==0) turn=1; else turn=0;} } private boolean anotherTurn(int pitNum) {pitNum--; boolean temp=false; if(turn==0) {if(pitNum==6) {turn=0; temp=true; } } else if(pitNum==-1) {turn=1; temp=true; } return temp; } private void capture(int pitNum, int pit) { pitNum--; if(turn==0){ if(sidePit[pitNum]==1 && pitNum<6) { if(pitNum==0) { sidePit[6]=sidePit[6]+sidePit[12]+1; sidePit[12]=0; } else if(pitNum==1) { sidePit[6]=sidePit[6]+sidePit[11]+1; sidePit[11]=0; } else if(pitNum==2) { sidePit[6]=sidePit[6]+sidePit[10]+1; sidePit[10]=0; } else if(pitNum==3) { sidePit[6]=sidePit[6]+sidePit[9]+1; sidePit[9]=0; } else if(pitNum==4) { sidePit[6]=sidePit[6]+sidePit[8]+1; sidePit[8]=0; } else if(pitNum==5) { sidePit[6]=sidePit[6]+sidePit[7]+1; sidePit[7]=0; } sidePit[pitNum]=0; } } if(turn==1) { //pitNum=pitNum; if(sidePit[pitNum]==1 && pit+7>6) { if(pitNum==7) { sidePit[13]=sidePit[13]+sidePit[5]+1; sidePit[7]=0; } else if(pitNum==8) { sidePit[13]=sidePit[13]+sidePit[4]+1; sidePit[4]=0; } else if(pitNum==9) { sidePit[13]=sidePit[13]+sidePit[3]+1; sidePit[3]=0; } else if(pitNum==10) { sidePit[13]=sidePit[13]+sidePit[2]+1; sidePit[2]=0; } else if(pitNum==11) { sidePit[13]=sidePit[13]+sidePit[1]+1; sidePit[1]=0; } else if(pitNum==12) { sidePit[13]=sidePit[13]+sidePit[0]+1; sidePit[0]=0; } sidePit[pitNum]=0; } } } } import java.io.BufferedReader; import java.io.InputStreamReader; public class RandomPlayer extends KalaPlayer{ //KalaGameState state; public int chooseMove(KalaGameState gs) throws NoMoveAvailableException {int[] moves; moves=getMoves(gs); try{ for(int i=0;i<=5;i++) System.out.println(moves[i]); for(int i=0;i<=5;i++) { if(moves[i]==1) { KalaGameState state=(KalaGameState) gs.clone(); state.makeMove(moves[i]); gs.getTurn(); moves[i]=evalValue(state.getScore(0),state.getScore(1)); } } } catch(IllegalMoveException e) { System.out.println(e); //chooseMove(state); } return 10; } private int evalValue(int score0,int score1) { int score=0; //int score0=0; // int score1=0; //getScore(0); //score1=state.getScore(1); //if((state.getTurn())==0) score=score1-score0; //else //score=score1-score0; System.out.println("score: "+score); return score; } public int[] getMoves(KalaGameState gs) { int[] moves=new int[6]; for(int i=1;i<=6;i++) { if(gs.getNumStones(i)!=0) moves[i-1]=1; else moves[i-1]=0; } return moves; } } Can you explain what is going wrong, please?

    Read the article

1