Update ooo320-m1
[ooovba.git] / sc / source / core / inc / sctictac.hxx
blobcf1ae3377e7d45c198ece4aee242b29b4932f504
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: sctictac.hxx,v $
10 * $Revision: 1.4 $
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
35 #ifdef TICTACTOE_MAIN
36 #define TICTACTOE_STDOUT
37 #else
38 //#define TICTACTOE_STDOUT
39 #endif
40 #ifndef TICTACTOE_STDOUT
41 #define TICTACTOE_SC
42 #endif
44 #ifdef TICTACTOE_SC
45 class ScDocument;
46 #include "global.hxx"
47 #include "address.hxx"
48 #else
49 #include <tools/string.hxx>
50 #endif
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];
57 class ScTicTacToe
59 private:
60 /* Structure to hold a move and its heuristic */
61 typedef struct {
62 int Square;
63 int 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 */
72 Board_Type Board;
73 #ifdef TICTACTOE_SC
74 ScAddress aPos; // linke obere Ecke des Boards
75 ScDocument* pDoc;
76 #endif
77 ByteString aStdOut;
78 int Total_Nodes; /* Nodes searched with minimax */
79 int nMove;
80 Square_Type aPlayer;
81 BOOL bInitialized;
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];
90 Square_Type Winner();
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()
99 void PromptHuman();
100 #ifdef TICTACTOE_SC
101 // -1 == Fehler/Redraw, 0 == keine Aenderung, >0 == UserMoveSquare+1
102 int GetStatus();
103 void DrawBoard();
104 void DrawPos( int nSquare, const String& rStr );
105 #endif
106 #ifdef TICTACTOE_STDOUT
107 void Print();
108 #endif
110 ScTicTacToe( const ScTicTacToe& );
111 ScTicTacToe& operator=( const ScTicTacToe& );
113 public:
114 #ifdef TICTACTOE_SC
115 ScTicTacToe( ScDocument* pDoc, const ScAddress& );
116 #else
117 ScTicTacToe();
118 #endif
119 ~ScTicTacToe() {}
120 void Initialize( BOOL bHumanFirst );
121 Square_Type GetEmpty() { return Empty; }
122 #ifdef TICTACTOE_SC
123 Square_Type CalcMove(); // return Winner()
124 #endif
125 #ifdef TICTACTOE_STDOUT
126 void Game();
127 void GetOutput( ByteString& rStr );
128 #else
129 void GetOutput( String& rStr );
130 #endif
133 #endif