package org.amc.game.chessserver;

import org.amc.game.chess.ChessBoard;
import org.amc.game.chess.ChessGame;
import org.amc.game.chess.ChessGamePlayer;
import org.amc.game.chess.Colour;
import org.amc.game.chess.ComparePlayers;
import org.amc.game.chess.Player;
import org.amc.game.chess.SetupChessBoard;
import org.apache.log4j.Logger;

import javax.persistence.Entity;

@Entity
public class TwoViewServerChessGame extends ServerChessGame {

    private static final long serialVersionUID = 4322777387785605817L;
    private static final Logger logger = Logger.getLogger(TwoViewServerChessGame.class);
    
    public TwoViewServerChessGame() {
        super();
    }
    
    public TwoViewServerChessGame(long uid, Player player) {
        super(uid, player);
      
    }
    
    public TwoViewServerChessGame(long uid, ChessGame chessGame) {
        super(uid, chessGame);
    }
    
    /**
     * Adds player to the black side of the chess game
     * Only valid if ServerChessGame is in AWAITING_PLAYER state, no exception
     * is thrown if not in that state
     * 
     * @param opponent
     *            Player
     */
    public void addOpponent(Player opponent) {
        checkForNull(Player.class, opponent);
        if (ServerGameStatus.AWAITING_PLAYER.equals(getCurrentStatus())) {
            if (ComparePlayers.comparePlayers(getPlayer(), opponent)) {
                logger.debug(String.format("Player:(%s) tried to join their own game",
                                opponent.getName()));
            } else {
                ChessBoard board = new ChessBoard();
                SetupChessBoard.setUpChessBoardToDefault(board);
                synchronized (this) {
                    setChessGame(getChessGameFactory().getChessGame(board, getPlayer(), 
                                    new ChessGamePlayer(opponent, Colour.BLACK)));
                    setCurrentStatus(ServerGameStatus.IN_PROGRESS);
                }
                notifyObservers(opponent);
            }
        }
    }
}

@@ -1237,66 +1237,29 @@
 if (
-ServerGameStatus.AWAITING_PLAYER.equals(getCurrentStatus()
+isGameAwaitingPlayer(
 )) %7B
@@ -1493,32 +1493,284 @@
  else %7B%0A        
+        setupChessGame(opponent);%0A            %7D%0A        %7D%0A    %7D%0A    %0A    private boolean isGameAwaitingPlayer() %7B%0A        return ServerGameStatus.AWAITING_PLAYER.equals(getCurrentStatus());%0A    %7D%0A    %0A    private void setupChessGame(Player opponent) %7B%0A
         ChessBoa
@@ -1798,24 +1798,16 @@
 oard();%0A
-        
         
@@ -1855,24 +1855,16 @@
 board);%0A
-        
         
@@ -1893,32 +1893,24 @@
             
-  
-      
 setChessGame
@@ -1994,24 +1994,16 @@
         
-        
 new Ches
@@ -2049,32 +2049,24 @@
             
-       
- 
 setCurrentSt
@@ -2113,28 +2113,18 @@
     
-        %7D%0A  
+%7D%0A
         
     
@@ -2119,22 +2119,16 @@
         
-      
 notifyOb
@@ -2150,32 +2150,8 @@
 t);%0A
-            %7D%0A        %7D%0A
     

refactor move method