private static PartialResults CheckDiagonals(FourInARowState state) { PartialResults summary = new PartialResults(); //// from left bottom to right top for (Int32 startY = 0, mStartY = FourInARowState.RowCount - WinningCount + 1; startY < mStartY; startY++) { FieldContext context = new FieldContext(); for (Int32 x = 0, y = startY, my = FourInARowState.RowCount, mx = FourInARowState.ColumnCount; y < my && x < mx /* && y < state.LastEmptyRow */; x++, y++) { ProcessField(state, x, y, context); } summary.Add(context.PartialResults); } for (Int32 startX = 1, mStartX = FourInARowState.ColumnCount - WinningCount + 1; startX < mStartX; startX++) { FieldContext context = new FieldContext(); for (Int32 x = startX, y = 0, my = FourInARowState.RowCount, mx = FourInARowState.ColumnCount; y < my && x < mx /* && y < state.LastEmptyRow */; x++, y++) { ProcessField(state, x, y, context); } summary.Add(context.PartialResults); } //// from right bottom to left top for (Int32 startY = 0, mStartY = FourInARowState.RowCount - WinningCount + 1; startY < mStartY; startY++) { FieldContext context = new FieldContext(); for (Int32 x = FourInARowState.ColumnCount - 1, y = startY, my = FourInARowState.RowCount; y < my && x >= 0 /* && y < state.LastEmptyRow */; x--, y++) { ProcessField(state, x, y, context); } summary.Add(context.PartialResults); } for (Int32 sStartX = FourInARowState.ColumnCount - 2, mStartX = WinningCount - 1; sStartX >= mStartX; sStartX--) { FieldContext context = new FieldContext(); for (Int32 x = sStartX, y = 0, my = FourInARowState.RowCount; y < my && x >= 0 /* && y < state.LastEmptyRow */; x--, y++) { ProcessField(state, x, y, context); } summary.Add(context.PartialResults); } return(summary); }
public Int32 Evaluate(IGameState gameState, GamePlayer player) { FourInARowState state = (FourInARowState)gameState; PartialResults summary = new PartialResults(); PartialResults result = CheckColumns(state); summary.Add(result); result = CheckRows(state); summary.Add(result); result = CheckDiagonals(state); summary.Add(result); return(CalculateScore(summary, player)); }
private static PartialResults CheckColumns(FourInARowState state) { PartialResults summary = new PartialResults(); for (Int32 x = 0, mx = FourInARowState.ColumnCount; x < mx; x++) { FieldContext context = new FieldContext(); for (Int32 y = 0, my = FourInARowState.RowCount; y < my /* && y < state.LastEmptyRow */; y++) { ProcessField(state, x, y, context); } summary.Add(context.PartialResults); } return(summary); }