The Pedigree Project  0.1
CmdLineInterface.cc
1 /*
2  *
3  * Copyright (c) 2008-2014, Pedigree Developers
4  *
5  * Please see the CONTRIB file in the root of the source tree for a full
6  * list of contributors.
7  *
8  * Permission to use, copy, modify, and distribute this software for any
9  * purpose with or without fee is hereby granted, provided that the above
10  * copyright notice and this permission notice appear in all copies.
11  *
12  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19  */
20 
21 #include "CmdLineInterface.h"
22 #include "Engine.h"
23 #include <stdio.h>
24 
25 CmdLineInterface::CmdLineInterface()
26 {
27 }
28 
29 CmdLineInterface::~CmdLineInterface()
30 {
31 }
32 
33 void CmdLineInterface::start(char argc, char **argv)
34 {
35  BoardState state = importState();
36  Engine engine;
37 // engine.state = state;
38 
39  engine.startSearch(White, 0, 40);
40 
41  while (!engine.searchComplete())
42  ;
43 
44  engine.stopSearch();
45  engine.printMoveList();
46 
47  engine.startSearch(White, 0, 4);
48 
49  while (!engine.searchComplete())
50  ;
51 
52  engine.stopSearch();
53  engine.printMoveList();
54 
55  engine.state.dump();
56 }
57 
58 BoardState CmdLineInterface::importState()
59 {
60  BoardState state;
61  state.white.pawns.clear(); state.white.knights.clear(); state.white.rooks.clear();
62  state.white.queen.clear(); state.white.king.clear(); state.white.bishops.clear();
63  state.black.pawns.clear(); state.black.knights.clear(); state.black.rooks.clear();
64  state.black.queen.clear(); state.black.king.clear(); state.black.bishops.clear();
65 
66  for (int i = 7; i >= 0; i--)
67  {
68  char c;
69  for(int j = 0; j < 8; j++)
70  {
71  fread(&c, 1, 1, stdin);
72  Square whiteSq(j, i);
73  Square blackSq = whiteSq;
74  blackSq.rotate180();
75  switch (c)
76  {
77  case 'P': state.black.pawns.set(blackSq.row, blackSq.col); break;
78  case 'R': state.black.rooks.set(blackSq.row, blackSq.col); break;
79  case 'B': state.black.bishops.set(blackSq.row, blackSq.col); break;
80  case 'H': state.black.knights.set(blackSq.row, blackSq.col); break;
81  case 'Q': state.black.queen.set(blackSq.row, blackSq.col); break;
82  case 'K': state.black.king.set(blackSq.row, blackSq.col); break;
83  case 'p': state.white.pawns.set(whiteSq.row, whiteSq.col); break;
84  case 'r': state.white.rooks.set(whiteSq.row, whiteSq.col); break;
85  case 'b': state.white.bishops.set(whiteSq.row, whiteSq.col); break;
86  case 'h': state.white.knights.set(whiteSq.row, whiteSq.col); break;
87  case 'q': state.white.queen.set(whiteSq.row, whiteSq.col); break;
88  case 'k': state.white.king.set(whiteSq.row, whiteSq.col); break;
89  }
90  }
91  fread(&c, 1, 1, stdin);
92  }
93  return state;
94 }
Bitboard pawns
Definition: SideState.h:100
bool searchComplete() volatile
Definition: Engine.cc:99
BoardState state
Definition: Engine.h:90
Definition: Engine.h:29
void stopSearch()
Definition: Engine.cc:94
void startSearch(Side s, int minD, int maxD)
Definition: Engine.cc:86
bool set(int rank, int file)
Definition: Bitboard.h:83
void dump()
Definition: BoardState.cc:657
Definition: Square.h:24
void printMoveList()
Definition: Engine.cc:113
bool clear(int rank, int file)
Definition: Bitboard.h:75