Implement representation for each positions

//records a board position and all moves made from that board by players public class GameTree { //GameBoard board; //for each possible board keep a record of the //statistics on each move seen from that board Dictionary<String, Dictionary<int, Tuple<GameMove, MoveStats>>> tree; //GameTree Parent; public Dictionary<String, Dictionary<int, Tuple<GameMove, MoveStats>>> Tree { get { return tree; } set { tree = value; } } //public GameBoard Board //{ // get { return board; } // set { board = value; } //} public GameTree() { Tree = new Dictionary<String, Dictionary<int, Tuple<GameMove, MoveStats>>>(); } GameTree(GameBoard brd) { Tree = new Dictionary<String, Dictionary<int, Tuple<GameMove, MoveStats>>>(); Tree.Add(brd.Key, new Dictionary<int, Tuple<GameMove, MoveStats>>()); } //add new move to GameTree internal MoveStats RegisterGameResult(BoardMove mv, bool win) // GameBoard brd, GameMove mv, bool win) { Tuple<GameMove, MoveStats> res = Tuple.Create(null as GameMove, null as MoveStats); if (tree.ContainsKey(mv.Board)) { //do we have this move registered for this board? var brdMoves = tree[mv.Board]; if (brdMoves.ContainsKey(mv.Move.Position)) { res = brdMoves[mv.Move.Position]; //register win res.Item2.RegisterResult(win); //store modified stats into moves dictionary brdMoves[mv.Move.Position] = res; //store modified move dictionary into boards disctionary tree[mv.Board] = brdMoves; } else { //no make new entry for this board and register win res = Tuple.Create(mv.Move, new MoveStats()); res.Item2.RegisterResult(win); //add stats to moves dictionary brdMoves.Add(mv.Move.Position, res); //add gamemove to board dictionary tree[mv.Board] = brdMoves; } //res.Parent = this; } else { //board not found create new board //create new move stat var mvStat = new MoveStats(); mvStat.RegisterResult(win); //create board entry //add to board dictionary var entry = new Dictionary<int, Tuple<GameMove, MoveStats>>() { { mv.Move.Position, Tuple.Create(mv.Move, mvStat) } };

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.