-
Notifications
You must be signed in to change notification settings - Fork 0
/
show_board.hpp
81 lines (69 loc) · 1.59 KB
/
show_board.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#ifndef TICTACTOE_SHOW_BOARD_HPP
#define TICTACTOE_SHOW_BOARD_HPP
#include "tictactoe.hpp"
#include <fas/type_list.hpp>
#include <fas/typemanip.hpp>
#include <iostream>
namespace std
{
std::ostream& operator<<(std::ostream& s, e)
{
s << "-";
return s;
}
std::ostream& operator<<(std::ostream& s, o)
{
s << "O";
return s;
}
std::ostream& operator<<(std::ostream& s, x)
{
s << "X";
return s;
}
template<typename L, typename R>
std::ostream& operator<<(std::ostream& s, fas::type_list<L, R>)
{
s << L();
int len = fas::length<R>::value;
if ( len%3 == 0 )
s << std::endl;
else if (len != 0)
s << " ";
s << R();
return s;
}
std::ostream& operator<<(std::ostream& s, fas::empty_list)
{
return s;
}
template<typename Pos, typename Fig, typename Board>
std::ostream& operator<< ( std::ostream& s, fas::tuple< Pos, Fig, Board> )
{
s << Board();
enum {
nopos = fas::same_type< Pos, fas::int_<-1> >::value,
nofig = fas::same_type< e, Fig>::value
};
if ( nopos )
{
if (nofig)
s << "Draw" << std::endl;
else
s << Fig() << " winner (you)" << std::endl;
}
else if ( !nofig )
{
s << Fig() << " winner (compiler)" << std::endl;
}
return s;
}
template<typename Pos, typename Fig, typename Board, typename Tail>
std::ostream& operator<<(std::ostream& s, fas::type_list<fas::tuple< Pos, Fig, Board>, Tail>)
{
s << fas::tuple<Pos, Fig, Board>() << std::endl;
s << Tail();
return s;
}
}
#endif