public MoveResult ApplyMove(Move move_to_apply) { get_square_unit_is_on(bender).visited_state = SquareVisitedState.last(); //Get the move result based on the current condition if (get_square_unit_is_on(bender).check_if_walls_prevent_move(move_to_apply)) { return(MoveResult.move_hit_wall()); //Walls prevent move } if (move_to_apply == Move.grab()) { if (get_square_unit_is_on(bender).beer_can_present) { collect_can(); return(MoveResult.can_collected()); } else { return(MoveResult.can_missing()); } } //Didn't try to grab a can, and didn't hit a wall. We moved successfully. MoveBender(move_to_apply); return(MoveResult.move_successful()); }
public SquareVisitedState visited_state; //Using a string to store one of three values: last move, unexplored, explored public BaseSquare() { bender_present = false; beer_can_present = false; visited_state = SquareVisitedState.unexplored(); //Deafult units_present = new Dictionary <Unit, bool>(); }
public void MoveBender(Move to_move) { get_square_unit_is_on(bender).bender_present = false; bender.x_coordinate += to_move.grid_adjustment[0]; bender.y_coordinate += to_move.grid_adjustment[1]; get_square_unit_is_on(bender).bender_present = true; get_square_unit_is_on(bender).visited_state = SquareVisitedState.last(); bender_percieves(); }
static SquareVisitedState() { last_state = new SquareVisitedState("Previous state"); explored_state = new SquareVisitedState("Explored state"); unexplored_state = new SquareVisitedState("Unexplored state"); list = new List <SquareVisitedState>(); list.Add(last_state); list.Add(explored_state); list.Add(unexplored_state); }
static Backgrounds() { last_move_bitmap = Properties.Resources.background_last_move; explored_bitmap = Properties.Resources.background_explored; unexplored_bitmap = Properties.Resources.background_unexplored; dictionary = new Dictionary <SquareVisitedState, System.Drawing.Bitmap>(); dictionary.Add(SquareVisitedState.last(), last_move_bitmap); dictionary.Add(SquareVisitedState.explored(), explored_bitmap); dictionary.Add(SquareVisitedState.unexplored(), unexplored_bitmap); }
//This is called each time we generate a new episode for our algorithm. //This is also called at the start of the program launch, disconnected from shuffling the whole board, just once. public void shuffle_bender() { //If Bender is already somewhere on the board, make sure we remove him from that location. if (get_square_unit_is_on(bender).bender_present) { board_data[bender.x_coordinate][bender.y_coordinate].bender_present = false; } //Get bender's new location. bender.x_coordinate = MyRandom.Next(0, 10); //0-9 inclusive bender.y_coordinate = MyRandom.Next(0, 10); get_square_unit_is_on(bender).bender_present = true; //Set bender get_square_unit_is_on(bender).visited_state = SquareVisitedState.last(); bender_percieves(); }
//Only called when we start a new episode //We need to reset the visited state as well public void shuffle_cans_and_bender() { //Activate the 50/50 chance for each tile to have beer in it. foreach (var i in board_data) { foreach (var j in i) { ((BoardSquare)j).randomize_beer_presence(); ((BoardSquare)j).visited_state = SquareVisitedState.unexplored(); } } shuffle_bender(); //Place bender randomly somewhere //get_square_unit_is_on().visited_state = SquareVisitedState.last(); }
//This is called when the algorithm has been reset public void ClearCans() { //Clear all cans foreach (var i in board_data) { foreach (var j in i) { j.beer_can_present = false; if (j.bender_present) { j.visited_state = SquareVisitedState.last(); } else { j.visited_state = SquareVisitedState.unexplored(); } } } }
//Copy constructor public GameBoard(GameBoard set_from) : base() { board_size = set_from.board_size; //Initialize 10x10 grid for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { board_data[i].Add(new BoardSquare((BoardSquare)set_from.board_data[i][j])); if (board_data[i][j].visited_state == SquareVisitedState.last() && !board_data[i][j].bender_present) { board_data[i][j].visited_state = SquareVisitedState.explored(); } } } add_walls(); bender = new Unit(set_from.bender); }
public BaseSquare(BaseSquare set_from) { bender_present = set_from.bender_present; beer_can_present = set_from.beer_can_present; visited_state = set_from.visited_state; }