Example #1
0
            private bool step(s_coordinate step_velocity)
            {
                List <s_coordinate> cleared_positions = new List <s_coordinate>();

                foreach (c_sea_cucumber sea_cucumber in sea_cucumbers)
                {
                    if (sea_cucumber.velocity.equals(step_velocity))
                    {
                        s_coordinate new_position = get_position_coordinates(
                            sea_cucumber.position.add(sea_cucumber.velocity));

                        if (positions[new_position.row][new_position.column] == null)
                        {
                            cleared_positions.Add(sea_cucumber.position);

                            sea_cucumber.position = new_position;
                            positions[new_position.row][new_position.column] = sea_cucumber;
                        }
                    }
                }

                bool any_moved = (cleared_positions.Count > 0);

                foreach (s_coordinate cleared_position in cleared_positions)
                {
                    positions[cleared_position.row][cleared_position.column] = null;
                }

                return(any_moved);
            }
Example #2
0
            public c_sea_floor(c_input_reader input_reader)
            {
                sea_cucumbers = new List <c_sea_cucumber>();

                List <c_sea_cucumber[]> position_list = new List <c_sea_cucumber[]>();

                s_coordinate position = new s_coordinate {
                    row = 0, column = 0
                };

                while (input_reader.has_more_lines())
                {
                    List <c_sea_cucumber> position_row_list = new List <c_sea_cucumber>();

                    position.column = 0;
                    foreach (char input_char in input_reader.read_line())
                    {
                        c_sea_cucumber sea_cucumber = null;

                        switch (input_char)
                        {
                        case '>':
                            sea_cucumber = new c_sea_cucumber {
                                position = position, velocity = k_east
                            };
                            break;

                        case 'v':
                            sea_cucumber = new c_sea_cucumber {
                                position = position, velocity = k_south
                            };
                            break;

                        case '.':
                            break;

                        default:
                            throw new Exception("Invalid input");
                        }

                        if (sea_cucumber != null)
                        {
                            sea_cucumbers.Add(sea_cucumber);
                        }

                        position_row_list.Add(sea_cucumber);

                        position.column++;
                    }

                    position_list.Add(position_row_list.ToArray());
                    position.row++;
                }

                positions = position_list.ToArray();
            }
Example #3
0
 public bool equals(s_coordinate other)
 {
     return(this.row == other.row && this.column == other.column);
 }
Example #4
0
 public s_coordinate add(s_coordinate other)
 {
     return(new s_coordinate {
         row = this.row + other.row, column = this.column + other.column
     });
 }
Example #5
0
 private s_coordinate get_position_coordinates(s_coordinate position)
 {
     return(new s_coordinate {
         row = position.row % positions.Length, column = position.column % positions[0].Length
     });
 }