Xiangiqgame
AI engine for Xiangqi
Loading...
Searching...
No Matches
move_evaluator_human_for_concepts.cpp
Go to the documentation of this file.
1
2#include <iostream>
3#include <memory>
6
7namespace moveselection {
8
9// HumanMoveEvaluator methods
10
12 gameboard::PieceColor evaluating_player,
13 std::istream &input_stream
14)
15 : evaluating_player_{evaluating_player}
16 , io_messages_{}
17 , input_stream_{input_stream} {}
18
19std::unique_ptr<HumanMoveEvaluatorForConcepts> HumanMoveEvaluatorForConcepts::Create(
20 gameboard::PieceColor evaluating_player,
21 std::istream &input_stream
22) {
23 return std::unique_ptr<HumanMoveEvaluatorForConcepts>(
24 new HumanMoveEvaluatorForConcepts(evaluating_player, input_stream)
25 );
26}
27
29 const gameboard::MoveCollection &allowed_moves
30) {
31
32 gameboard::Move legal_move;
33 bool legal_move_proposed = false;
34
35 while (!legal_move_proposed) {
36 auto proposed_move = GetSyntacticallyValidMove(input_stream_);
37 if (allowed_moves.ContainsMove(proposed_move)) {
38 legal_move_proposed = true;
39 legal_move = proposed_move;
40 } else {
42 }
43 }
44 return legal_move;
45}
46
49}
50
51// Factory methods
52
53std::unique_ptr<MoveEvaluatorBase> HumanMoveEvaluatorFactory::Create(
54 gameboard::PieceColor evaluating_player
55) {
57}
58
60 std::istream &input_stream
61) {
62 gameboard::Move result;
63
64 bool obtained_syntactically_valid_move = false;
65
66 while (!obtained_syntactically_valid_move) {
68 auto raw_input = movetranslation::GetInput(input_stream);
69 auto input_tokens = movetranslation::Tokenize(raw_input);
70 if (movetranslation::IsValidAlgebraicMove(input_tokens)) {
71 obtained_syntactically_valid_move = true;
72 auto algebraic_move = movetranslation::AlgebraicMove::Create(input_tokens);
73 result = algebraic_move.ToGameBoardMove();
74 } else {
76 }
77 }
78
79 return result;
80}
81
82} // namespace moveselection
83
84namespace humanplayerio {
86 std::cout << input_prompt_ << std::endl;
87}
88
90 std::cout << invalid_input_msg_ << std::endl;
91}
92
94 std::cout << illegal_move_msg_ << std::endl;
95}
96} // namespace humanplayerio
std::unique_ptr< MoveEvaluatorBase > Create(gameboard::PieceColor evaluating_player) override
gameboard::Move SelectMove(const gameboard::MoveCollection &allowed_moves)
static std::unique_ptr< HumanMoveEvaluatorForConcepts > Create(gameboard::PieceColor evaluating_player, std::istream &input_stream=std::cin)
HumanMoveEvaluatorForConcepts(gameboard::PieceColor evaluating_player, std::istream &input_stream)
gameboard::Move GetSyntacticallyValidMove(std::istream &input_stream)
static const AlgebraicMove Create(const std::vector< AlgebraicBoardSpace > &algebraic_board_spaces)
Selecting a move to execute.
bool IsValidAlgebraicMove(const std::vector< std::string > &tokens)
const std::string GetInput(std::istream &input_stream)
const std::vector< std::string > Tokenize(const std::string &input)
A container for multiple gameboard::Move objects.
bool ContainsMove(const Move &move) const
A gameboard::BoardSpace pair (start and end).