ttt_meta.cpp 1008 B

1234567891011121314151617181920212223242526272829
  1. //
  2. // Created by nositelshtanov on 11/11/2023.
  3. //
  4. #include "ttt_meta.h"
  5. void ttt_meta::step(std::size_t map_number, std::size_t field) {
  6. if (map_number >= map_size) { throw invalid_coords_error(); }
  7. if (next_map != any_map && map_number != next_map) { throw invalid_coords_error(); }
  8. if (get_winner() != mark::nothing || is_game_end()) { throw step_error{step_error::Reason::game_already_end}; }
  9. if (map[map_number].get_winner() != mark::nothing || map[map_number].get_mark(field) != mark::nothing) { throw step_error{step_error::Reason::the_field_is_occupied}; }
  10. map[map_number].step(whose_step, field);
  11. if (map[map_number].is_game_end())
  12. {
  13. auto winner = map[map_number].get_winner();
  14. if (winner != mark::nothing)
  15. {
  16. ttt_engine::step(whose_step, map_number);
  17. }
  18. }
  19. whose_step = whose_step == mark::cross ? mark::zero : mark::cross;
  20. if (map[field].is_game_end()) { next_map = any_map; }
  21. else { next_map = field; }
  22. }