Example #1
0
		}//end of constructor

		private void GetSetupInput() {
			Console.WriteLine("Would you liked to go first? (yes/no)");
			bool selectionMade = false;
			do {
				String goFirstResponse = Console.ReadLine();
				if(input_affirmative(goFirstResponse)) {
					selectionMade = true;
					Delinquent.GetGame().SetComputerColor(ConsoleColor.DarkGreen);
					Delinquent.GetGame().SetHumanColor(ConsoleColor.White);
					Delinquent.human_going_first = true;
				}
				else if(input_negative(goFirstResponse)) {
					selectionMade = true;
					Delinquent.GetGame().SetComputerColor(ConsoleColor.White);
					Delinquent.GetGame().SetHumanColor(ConsoleColor.DarkGreen);
					Delinquent.human_going_first = false;
				}
				else {
					Console.WriteLine("Invalid selection. Please try again.");
				}
			}
			while(!selectionMade);
			Console.Clear();
//			Console.WriteLine($"Human=>{Delinquent.GetGame().GetHumanPlayer()}");
//			Console.WriteLine($"Computer=>{Delinquent.GetGame().GetComputerPlayer()}");
		}//end of GetSetupInput method
Example #2
0
		}//end of DisplayRow2 method

		private void DisplayRow1() {
			Console.ForegroundColor = ConsoleColor.Black;
			Console.Write("\t8 ");
			char[] row1 = get_row_chars(0);
			for(int i = 0; i < 6; i++) {
				if(row1[i] == get_char_for_piece(Game.PIECES.NONE)) {
					Console.ForegroundColor = ConsoleColor.Black;
				}
				else if(Char.IsUpper(row1[i])) {
					if(Delinquent.GetGame().GetComputerPlayer() == Game.PLAYERS.P1) {
						Console.ForegroundColor = Delinquent.GetGame().GetComputerColor();
					}
					else {
						Console.ForegroundColor = Delinquent.GetGame().GetHumanColor();
					}
				}
				else {
					if(Delinquent.GetGame().GetComputerPlayer() == Game.PLAYERS.P2) {
						Console.ForegroundColor = Delinquent.GetGame().GetComputerColor();
					}
					else {
						Console.ForegroundColor = Delinquent.GetGame().GetHumanColor();
					}
				}
				Console.Write(row1[i]);
				Console.Write(' ');
			}
			Console.WriteLine();
		}//end of DisplayRow1 method
Example #3
0
		}//end of GetComputerMove method

		public int[] GetRANDComputerMove() {
			List<Move> moves = Delinquent.GetGame().MoveGenerator(Delinquent.GetGame().GetComputerPlayer());
			int number = moves.Count();
			Random rng = new Random();
			int randIndex = rng.Next(0, number);
			Move move = moves.ElementAt(randIndex);
			return move.ToArray();
		}//end of GetRANDComputerMove method
Example #4
0
		}//end of DisplayResult method

		private static char[] get_row_chars(int row) {
			char[] returnValue = new char[6];
			Game.PIECES[] rowPieces = Delinquent.GetGame().GetBoardRow(row);
			for(int i=0; i < 6; i++) {
				returnValue[i] = get_char_for_piece(rowPieces[i]);
			}
			return returnValue;
		}//end of get_row_chars method
Example #5
0
		}//end of DisplayColumLabels method

		public void DisplayResult() {
			string winner = "";
			Console.ForegroundColor = ConsoleColor.Red;
			if(Delinquent.GetGame().GetWinner() == Delinquent.GetGame().GetHumanPlayer()) {
				winner = "The Human";
			}
			else if(Delinquent.GetGame().GetWinner() == Delinquent.GetGame().GetComputerPlayer()) {
				winner = "Delinquent";
			}
			else {
				winner = "Nobody";
			}
			Console.WriteLine($"Game Over! {winner} has won!");
			Console.ForegroundColor = ConsoleColor.Black;
			Console.WriteLine();
			Console.WriteLine("Press [Enter] to quit.");
		}//end of DisplayResult method
Example #6
0
		}//end of Max method

		private int Min(int max) {
			int returnValue = int.MaxValue;
			if(turnTimer.Elapsed.TotalMilliseconds >= maxTurnTime) {
				timeExpired = true;
				return returnValue;
			}
			currentDepth++;
			Game.PLAYERS human = Delinquent.GetGame().GetHumanPlayer();
			List<Move> moves = Delinquent.GetGame().MoveGenerator(Delinquent.GetGame().GetHumanPlayer());
			if(human == Game.PLAYERS.P1) {
				if(moves.Count == 0 || Delinquent.GetGame().PeekRemoval().GetPiece() == Game.PIECES.P1_KING) {
					returnValue = 999999999;
				}
			}
			else {
				if(moves.Count == 0 || Delinquent.GetGame().PeekRemoval().GetPiece() == Game.PIECES.P2_KING) {
					returnValue = 999999999;
				}
			}
			if(returnValue != 999999999) {
				if(currentDepth == maxDepth) {
					returnValue = Eval(moves, false);
				}
				else {
					foreach(Move move in moves) {
						if(timeExpired) {
							break;
						}
						Delinquent.GetGame().TryMove(move);
						int moveScore = Max(returnValue);
						if(moveScore < returnValue) {
							returnValue = moveScore;
						}
						Delinquent.GetGame().UndoMove(move);
						if(returnValue < max) {
							break;
						}
					}
				}
			}
			currentDepth--;
			return returnValue;
		}//end of Min method
Example #7
0
		}//end of GetSetupInput method

		public int[] GetUserMove() {
			int[] move;
			bool validMoveReceived = false;
			do {
				Console.ForegroundColor = ConsoleColor.Black;
				Console.WriteLine("Enter a move: ");
				string moveString = Console.ReadLine();
				move = map_move_string(moveString);
//				Console.WriteLine($"Move=[{move[0]}],[{move[1]}],[{move[2]}],[{move[3]}]");
				Game.PLAYERS human = Delinquent.GetGame().GetHumanPlayer();
//				Console.WriteLine($"Human={human}");
				validMoveReceived = Delinquent.GetGame().IsMoveLegal(move, human);
				if(!validMoveReceived) {
					Console.WriteLine("Entered move not legal. Please try again.");
				}
			}
			while(!validMoveReceived);
			return move;
		}//end of GetUserMove method
Example #8
0
		}//end of GetRANDComputerMove method

		private Move Minimax() {
			Move returnValue = null;
			int bestScore = int.MinValue;
			List<Move> moves = Delinquent.GetGame().MoveGenerator(Delinquent.GetGame().GetComputerPlayer());
			foreach(Move move in moves) {
				if(timeExpired) {
					break;
				}
				currentDepth = 1;
				Delinquent.GetGame().TryMove(move);
				int moveScore = Min(bestScore);
				if(moveScore > bestScore) {
					returnValue = move;
					bestScore = moveScore;
				}
				Delinquent.GetGame().UndoMove(move);
			}
			if(timeExpired) {
				returnValue = null;
			}
			return returnValue;
		}//end of Minimax method
Example #9
0
		}//end of Min method

		private int Eval(List<Move> moves, bool forComputer) {
			int returnValue = 0;
			bool useTrans = false;
			long transKey = Delinquent.GetGame().GetCurrentHash();
			if(transTable.ContainsKey(transKey)) {
				Transposition trans = transTable[transKey];
				if(trans.Ply() <= currentDepth) {
					returnValue = trans.Score();
					useTrans = true;
				}
			}
			if(!useTrans) {
				Game.PLAYERS human = Delinquent.GetGame().GetHumanPlayer();
				Game.PLAYERS computer = Delinquent.GetGame().GetComputerPlayer();
				List<Move> computerMoves;
				List<Move> humanMoves;
				if(forComputer) {
					computerMoves = moves;
					humanMoves = Delinquent.GetGame().MoveGenerator(human);
				}
				else {
					humanMoves = moves;
					computerMoves = Delinquent.GetGame().MoveGenerator(computer);
				}
				//piece value + board advance + mobility + piece threat
				if(human == Game.PLAYERS.P1) {
					int p1Score = EvalP1Score(humanMoves);
					int p2Score = EvalP2Score(computerMoves);
					returnValue = p2Score - p1Score;
				}
				else {
					int p1Score = EvalP1Score(computerMoves);
					int p2Score = EvalP2Score(humanMoves);
					returnValue = p1Score - p2Score;
				}
				transTable[transKey] = new Transposition(currentDepth, returnValue);
			}
			return returnValue;
		}//end of Eval method
Example #10
0
			}//end of (int,int) constructor

			public Target(Move move) {
				this.row = move.GetToRow();
				this.col = move.GetToCol();
				piece = Delinquent.GetGame().PieceAt(row, col);
			}//end of (Move) constructor
Example #11
0
			}//end of (int,int) constructor

			public Pos(Move move) {
				this.row = move.GetFromRow();
				this.col = move.GetFromCol();
				this.piece = Delinquent.GetGame().PieceAt(row, col);
			}//end of (Move) constructor