1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: sctictac.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef SC_SCTICTAC_HXX
32 #define SC_SCTICTAC_HXX
34 //#define TICTACTOE_MAIN
36 #define TICTACTOE_STDOUT
38 //#define TICTACTOE_STDOUT
40 #ifndef TICTACTOE_STDOUT
47 #include "address.hxx"
49 #include <tools/string.hxx>
52 static const int ScTicTacToe_Squares
= 9;
53 static const int ScTicTacToe_Possible_Wins
= 8;
54 typedef sal_Unicode Square_Type
;
55 typedef Square_Type Board_Type
[ScTicTacToe_Squares
];
60 /* Structure to hold a move and its heuristic */
64 } Move_Heuristic_Type
;
66 static const Square_Type Empty
;
67 static const Square_Type Human
;
68 static const Square_Type Compi
;
69 static const int Infinity
; /* Higher value than any score */
70 static const int Maximum_Moves
; /* Maximum moves in a game */
74 ScAddress aPos
; // linke obere Ecke des Boards
78 int Total_Nodes
; /* Nodes searched with minimax */
83 /* Array describing the eight combinations of three squares in a row */
84 static const int Three_in_a_Row
[ScTicTacToe_Possible_Wins
][3];
86 /* Array used in heuristic formula for each move. */
87 static const int Heuristic_Array
[4][4];
91 inline Square_Type
Other( Square_Type Player
);
92 inline void Play( int Square
, Square_Type Player
);
93 int Evaluate( Square_Type Player
);
94 int BestMove( Square_Type Player
, int *Square
,
95 int Move_Nbr
, int Alpha
, int Beta
);
96 void Describe( int Score
);
97 void Move( int& Square
);
98 Square_Type
TryMove( int& Square
); // return Winner()
101 // -1 == Fehler/Redraw, 0 == keine Aenderung, >0 == UserMoveSquare+1
104 void DrawPos( int nSquare
, const String
& rStr
);
106 #ifdef TICTACTOE_STDOUT
110 ScTicTacToe( const ScTicTacToe
& );
111 ScTicTacToe
& operator=( const ScTicTacToe
& );
115 ScTicTacToe( ScDocument
* pDoc
, const ScAddress
& );
120 void Initialize( BOOL bHumanFirst
);
121 Square_Type
GetEmpty() { return Empty
; }
123 Square_Type
CalcMove(); // return Winner()
125 #ifdef TICTACTOE_STDOUT
127 void GetOutput( ByteString
& rStr
);
129 void GetOutput( String
& rStr
);