package at.wwoe.schnapsen.model.game;

import at.wwoe.schnapsen.controller.player.Player;
import at.wwoe.schnapsen.model.card.Suit;

public class MoveEval {
	
	public MoveResult get(Player playerInitial, Player playerOther, Move movePlayerInitial, Move movePlayerOther, Suit adout) {
		
		MoveResult moveResult;
		int pairInitial = 0;
		int pairOther = 0;
		int cardPoints = movePlayerInitial.getCard().getValue() + 
				         movePlayerOther.getCard().getValue();		
		
		if(movePlayerInitial.getShowPair()) {
			if(movePlayerInitial.getCard().getSuit().equals(adout)) {
				pairInitial = 40;
			}
			else {
				pairInitial = 20;
			}
		}

		if(movePlayerOther.getShowPair()) {
			if(movePlayerOther.getCard().getSuit().equals(adout)) {
				pairOther = 40;
			}
			else {
				pairOther = 20;
			}
		}
		
		if(movePlayerInitial.getCard().getSuit().equals(adout)) {
			if(movePlayerOther.getCard().getSuit().equals(adout)) {
				if(movePlayerInitial.getCard().getValue() > movePlayerOther.getCard().getValue()) {
					
					moveResult = new MoveResult(playerInitial, playerOther,
							cardPoints, pairInitial, pairOther);
							
				}
				else {

					moveResult = new MoveResult(playerOther, playerInitial,
							cardPoints, pairOther, pairInitial);

				}
			}
			else {

				moveResult = new MoveResult(playerInitial, playerOther,
						cardPoints, pairInitial, pairOther);
				
			}
		}
		else {
			if(movePlayerOther.getCard().getSuit().equals(adout)) {

				moveResult = new MoveResult(playerOther, playerInitial,
						cardPoints, pairOther, pairInitial);

			}
			else {
				if(movePlayerInitial.getCard().getSuit().equals(movePlayerOther.getCard().getSuit()))
				{
					if(movePlayerInitial.getCard().getValue() > movePlayerOther.getCard().getValue()) {

						moveResult = new MoveResult(playerInitial, playerOther,
								cardPoints, pairInitial, pairOther);

					}
					else {

						moveResult = new MoveResult(playerOther, playerInitial,
								cardPoints, pairOther, pairInitial);

					}
				}
				else {

					moveResult = new MoveResult(playerInitial, playerOther,
							cardPoints, pairInitial, pairOther);
					
				}
			}
		}
		
		return moveResult;
	}
}
