package com.meta1203.ChessPlayer;

import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;

/*
 * Lovingly yanked from https://github.com/gt4dev/yet-another-tree-structure
 */

public class Turn implements Comparable <Turn>, Comparator<Turn> {

	private Board board;
	private Turn parent;
	private boolean whiteTurn;
	private List<Turn> children;
	private int depth;

	public Turn(Board data) {
		this.board = data;
		this.children = new LinkedList<Turn>();
		this.depth = 1;
		this.parent = null;
		this.whiteTurn = true;
	}
	
	public Turn(Board data, int depth, boolean white) {
		this.board = data;
		this.children = new LinkedList<Turn>();
		this.depth = depth;
	}

	public Turn addChild(Board child) {
		Turn childNode = new Turn(child, this.depth + 1, !this.whiteTurn);
		childNode.parent = this;
		this.children.add(childNode);
		return childNode;
	}
	
	public void sort() {
		if (children.isEmpty()) return;
		Collections.sort(children);
		for (Turn x : children) {
			x.sort();
		}
	}
	
	// Getters
	public Board getBoard() {
		return board;
	}
	public Turn getParent() {
		return parent;
	}
	public List<Turn> getChildren() {
		return children;
	}
	public boolean isWhiteTurn() {
		return whiteTurn;
	}
	
	// Comparison
	@Override
	public int compare(Turn one, Turn another) {
		// Weigh both points and # of turns made
		// Score = Black point value - # of turns - White point value
		return (one.board.getBlackPointValue()-one.depth-one.board.getWhitePointValue())
				-(another.board.getBlackPointValue()-another.depth-another.board.getWhitePointValue());
	}

	@Override
	public int compareTo(Turn other) {
		return this.compare(this, other);
	}
}
@@ -1268,358 +1268,412 @@
 %0A%09%0A%09
-// Comparison%0A%09@Override%0A%09public int compare(Turn one, Turn another) %7B%0A%09%09// Weigh both points and # of turns made%0A%09%09// Score = Black point value - # of turns - White point value%0A%09%09return (one.board.getBlackPointValue()-one.depth-one.board.getWhitePointValue())%0A%09%09%09%09-(another.board.getBlackPointValue()-another.depth-another.board.getWhitePointValue()
+public int getValue() %7B%0A%09%09int ret = this.board.getBlackPointValue() - this.board.getWhitePointValue();%0A%09%09// Point values should decrease exponentially by turn%0A%09%09for (Turn x : this.getChildren()) %7B%0A%09%09%09ret += x.getValue()/2;%0A%09%09%7D%0A%09%09return ret;%0A%09%7D%0A%09%0A%09// Comparison%0A%09@Override%0A%09public int compare(Turn one, Turn another) %7B%0A%09%09// Weigh both points and # of turns made%0A%09%09return one.getValue() - another.getValue(
 );%0A%09

Modify the comparisons so that later turns are taken into account