import org.json.*;

import java.io.FileWriter;
import java.io.IOException;
import java.util.Map;

public class Record {
    private JSONObject j;
    private JSONArray a;
    private Map m;

    public void saveRecord(String filename, String Winner, String Loser, short WinChess, BWChess[][] ChessStatus){
        j = new JSONObject();
        // Info
        j.put("Winner", Winner);
        j.put("Loser", Loser);
        j.put("WinChess", WinChess);

        // Chess
        a = new JSONArray();
        JSONArray ChessArray = new JSONArray();
        JSONObject Chess = new JSONObject();
        for(int i=0;i<ChessStatus.length;i++){
            for(int j=0;j<ChessStatus.length;j++){
                if (ChessStatus[i][j] != null){
                    Chess.put("Color", ChessStatus[i][j].getColor());
                    JSONObject ChessLoc = new JSONObject();
                    ChessLoc.put("x", ChessStatus[i][j].getLoc().getX());
                    ChessLoc.put("y", ChessStatus[i][j].getLoc().getY());
                    Chess.put("Location", ChessLoc);
                    Chess.put("Step", ChessStatus[i][j].getStep());
                    ChessArray.put(Chess);
                }
            }
            if (ChessArray.length() != 0){
                a.put(ChessArray);
            }
        }
        j.put("ChessStatus", a);

        // Save to file
        JSONWriter writer = null;
        try {
            writer = new JSONWriter(new FileWriter(filename));
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (writer!=null){
            writer.value(j);
            writer.endObject();
        }
    }

    public Object readRecord(String filename){
        return new Object();
    }
}

@@ -89,104 +89,194 @@
 til.
-Map;%0A%0Apublic class Record %7B%0A    private JSONObject j;%0A    private JSONArray a;%0A    private Map m
+ArrayList;%0Aimport java.util.Iterator;%0Aimport java.util.Map;%0A%0Apublic class Record %7B%0A    private String blackChess;%0A    private String whiteChess;%0A    private ArrayList%3CChess%3E chessHistory
 ;%0A%0A 
@@ -289,17 +289,8 @@
 lic 
-void save
 Reco
@@ -303,197 +303,95 @@
 ing 
-filename, String Winner, String Loser, short WinChess, BWChess%5B%5D%5B%5D ChessStatus)%7B%0A        j = new JSONObject();%0A        // Info%0A        j.put(%22Winner%22, Winner);%0A        j.put(%22Loser%22, Los
+blackChessPlayer, String whiteChessPlayer) %7B%0A        this.blackChess = blackChessPlay
 er
-)
 ;%0A  
@@ -400,119 +400,76 @@
     
-j.put(%22WinChess%22, WinChess);%0A%0A        // Chess%0A        a = new JSONArray();%0A        JSONArray ChessArra
+this.whiteChess = whiteChessPlayer;%0A        this.chessHistor
 y = new 
 JSON
@@ -468,25 +468,27 @@
 new 
-JSON
 Array
+List%3C%3E
 ();%0A    
     
@@ -487,944 +487,447 @@
     
+%7D%0A%0A
     
-JSONObject Chess = new JSONObject();%0A        for(int i=0;i%3CChessStatus.length;i++)%7B%0A            for(int j=0;j%3CChessStatus.length;j++)%7B
+public void addRecord(Chess chess) %7B%0A        this.chessHistory.add(chess);
 %0A    
+%7D%0A%0A
     
-        if (ChessStatus%5Bi%5D%5Bj%5D != null)%7B%0A                    Chess.put(%22Color%22, ChessStatus%5Bi%5D%5Bj%5D.getColor());%0A                    JSONObject ChessLoc = new JSONObject();%0A                    ChessLoc.put(%22x%22, ChessStatus%5Bi%5D%5Bj%5D.getLoc().getX());%0A                    ChessLoc.put(%22y%22, ChessStatus%5Bi%5D%5Bj%5D.getLoc().getY());%0A                    Chess.put(%22Location%22, ChessLoc);%0A                    Chess.put(%22Step%22, ChessStatus%5Bi%5D%5Bj%5D.getStep());%0A                    ChessArray.put(Chess);%0A                %7D%0A            %7D%0A            if (ChessArray.length() != 0)%7B%0A                a.put(ChessArray);%0A            %7D%0A        %7D%0A        j.put(%22ChessStatus%22, a);%0A%0A        // Save to file%0A        JSONWriter writer = null;%0A        try %7B%0A            writer = new JSONWriter(new FileWriter(filename
+public void push(Chess chess) %7B%0A        this.addRecord(chess);%0A    %7D%0A%0A    public Chess lastRecord() %7B%0A        return new BWChess(this.chessHistory.get(this.chessHistory.size() - 1));%0A    %7D%0A%0A    public Chess top() %7B%0A        return this.lastRecord();%0A    %7D%0A%0A    public void removeRecord() %7B%0A        this.chessHistory.remove(this.lastRecord(
 ));%0A    
     
@@ -926,75 +926,68 @@
     
+%7D%0A%0A
     
-%7D catch (IOException e) %7B%0A            e.printStackTrace
+public void pop() %7B%0A        this.removeRecord
 ();%0A    
     
@@ -986,199 +986,161 @@
     
-  
-  
 %7D
+%0A
 %0A    
-    if (writer!=null)%7B%0A            writer.value(j);%0A            writer.endObject();%0A        %7D%0A    %7D%0A%0A    public Object readRecord(String filename)%7B%0A        return new Object();
+public void saveRecord() %7B%0A        // TODO: Save to file or DB%0A    %7D%0A%0A    public void loadRecord() %7B%0A        // TODO: Load from file or DB
 %0A    %7D%0A
+%0A%0A%0A
 %7D%0A

Rewrite Record