summaryrefslogtreecommitdiff
path: root/player.h
blob: 0c369c86cebb00be980f205561738c7fd45d2e0f (plain)
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
 *  Quackle -- Crossword game artificial intelligence and analysis tool
 *  Copyright (C) 2005-2006 Jason Katz-Brown and John O'Laughlin.
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  
 *  02110-1301  USA
 */

#ifndef QUACKLE_PLAYER_H
#define QUACKLE_PLAYER_H

#include "rack.h"
#include "uv.h"

namespace Quackle
{

class ComputerPlayer;

class Player
{
public:
	enum PlayerType { ComputerPlayerType = 0, HumanPlayerType = 1};

	// creates a Computer player whose id is -1 and zero score
	Player();

	// creates a player with zero score
	Player(const UVString &name, int playerType = HumanPlayerType, int id = -1);

	void setName(const UVString &newName) { m_name = newName; }
	const UVString &name() const { return m_name; }

	void setAbbreviatedName(const UVString &newAbbreviatedName) { m_abbreviatedName = newAbbreviatedName; }
	const UVString &abbreviatedName() const { return m_abbreviatedName; }

	void setType(int playerType) { m_playerType = playerType; }
	int type() const { return m_playerType; }

	void setComputerPlayer(ComputerPlayer *computerPlayer) { m_computerPlayer = computerPlayer; }
	ComputerPlayer *computerPlayer() const { return m_computerPlayer; }

	// ID of real players must be greater than zero
	int id() const { return m_id; }

	// This never needs to be called by users!
	void setId(int id) { m_id = id; }

	void setRack(const Rack &newRack) { m_rack = newRack; }
	void setRack(const LetterString &rack) { m_rack = Rack(rack); }
	const Rack &rack() const { return m_rack; }

	void setScore(int score) { m_score = score; }
	int score() const { return m_score; }

	// addition = negative -> subtract from score
	void addToScore(int addition);

	// what was drawn to get TO this rack
	const Rack &drawnLetters() const { return m_drawnLetters; }
	void setDrawnLetters(const Rack &drawnLetters) { m_drawnLetters = drawnLetters; }

	// not used by libquackle -- whether the racks of this player are gibberish
	// or correct correspondents to real life
	bool racksAreKnown() const { return m_racksAreKnown; }
	void setRacksAreKnown(bool racksAreKnown) { m_racksAreKnown = racksAreKnown; }

	// returns true if rack, score are equal
	bool positionallyEqual(const Player &otherPlayer) const;

	UVString storeInformationToString() const;

	// these do no error checking!!! careful!
	void loadInformationFromString(const UVString &info);
	static Player makePlayerFromString(const UVString &info);

private:
	UVString m_name;
	UVString m_abbreviatedName;
	int m_id;
	int m_playerType;
	ComputerPlayer *m_computerPlayer;

	Rack m_rack;
	int m_score;

	Rack m_drawnLetters;
	bool m_racksAreKnown;
};

}

// comparison based on player ID
inline bool operator<(const Quackle::Player &player1, const Quackle::Player &player2)
{
	return player1.id() < player2.id();
}

inline bool operator==(const Quackle::Player &player1, const Quackle::Player &player2)
{
	return player1.id() == player2.id();
}

UVOStream &operator<<(UVOStream &o, const Quackle::Player &player);

#endif