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 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 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(); }
//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); }