- Implemented saving and loading of a player model. High scores are now persistent, though only for one user.
- Created a JUnit test class to test the serialization. Should be useful for later tests.
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
package model.playerModel;
|
||||
|
||||
public class GameLog implements Comparable<GameLog> {
|
||||
import java.io.Serializable;
|
||||
|
||||
public class GameLog implements Comparable<GameLog>, Serializable {
|
||||
public static boolean SORT_BY_SCORE = true;
|
||||
private static final long serialVersionUID = 1L;
|
||||
private final int gameNum;
|
||||
|
||||
private final int score;
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package model.playerModel;
|
||||
|
||||
public interface Node {
|
||||
import java.io.Serializable;
|
||||
|
||||
public interface Node extends Serializable {
|
||||
|
||||
boolean axon();
|
||||
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
package model.playerModel;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@@ -31,8 +36,18 @@ public class PlayerModel implements Serializable {
|
||||
}
|
||||
|
||||
public static PlayerModel load() {
|
||||
// TODO Import the PlayerModel from a file.
|
||||
return new PlayerModel();
|
||||
FileInputStream fin = null;
|
||||
ObjectInputStream oin = null;
|
||||
|
||||
try {
|
||||
fin = new FileInputStream(PLAYER_MODEL_PATH);
|
||||
oin = new ObjectInputStream(fin);
|
||||
PlayerModel pm = (PlayerModel) oin.readObject();
|
||||
oin.close();
|
||||
return pm;
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private int GAME_COUNTER = 0;
|
||||
@@ -170,8 +185,17 @@ public class PlayerModel implements Serializable {
|
||||
}
|
||||
|
||||
public boolean save() {
|
||||
// TODO Implement saving.
|
||||
return false;
|
||||
FileOutputStream fout = null;
|
||||
ObjectOutputStream oout = null;
|
||||
try {
|
||||
fout = new FileOutputStream(PLAYER_MODEL_PATH);
|
||||
oout = new ObjectOutputStream(fout);
|
||||
oout.writeObject(this);
|
||||
oout.close();
|
||||
return true;
|
||||
} catch (IOException ex) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void train(boolean[] example) {
|
||||
|
||||
@@ -4,6 +4,7 @@ import model.playerModel.Node;
|
||||
|
||||
public class InputNode implements Node {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private boolean dendrite = false;
|
||||
|
||||
@Override
|
||||
|
||||
@@ -6,6 +6,8 @@ import model.playerModel.Node;
|
||||
|
||||
public class SigmoidNode implements Node {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
// Training rate.
|
||||
private final double A = .15;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user