Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Label set 2 #43

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion python/hcheckers/board.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ def draw_field(self, painter, field, row, col, hide=False):
else:
x = col * sz.cell_size
y = (self.n_rows-1-row) * sz.cell_size
field.draw(painter, QRect(sz.init_x + x, sz.init_y + y, sz.cell_size, sz.cell_size))
field.draw(painter, QRectF(sz.init_x + x, sz.init_y + y, sz.cell_size, sz.cell_size))
if hide:
field.hide_piece = prev_hide_piece
field.possible_piece = prev_possible_piece
Expand Down
14 changes: 9 additions & 5 deletions python/hcheckers/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ def run(self):
finally:
self.owner.move_lock.release()


class AI(object):
DEFAULT_TIMEOUT = 120*1000

def __init__(self, **kwargs):
self.title = "Default AI"
self.depth = 2
Expand All @@ -45,8 +48,8 @@ def __init__(self, **kwargs):
self.moves_bound_high = 8
self.start_depth = None
self.use_positional_score = True
self.timeout = None
self.use_timeout = False
self.timeout = AI.DEFAULT_TIMEOUT
self.deepening_within_timeout = False
self.random_opening_depth = 1
self.random_opening_options = 1

Expand Down Expand Up @@ -97,7 +100,7 @@ def from_settings(cls, settings):
ai.moves_bound_low = settings.value("moves_bound_low", type=int)
ai.moves_bound_high = settings.value("moves_bound_high", type=int)
ai.use_positional_score = settings.value("use_positional_score", type=bool)
ai.use_timeout = settings.value("use_timeout", type=bool)
ai.deepening_within_timeout = settings.value("use_timeout", type=bool)
ai.timeout = settings.value("timeout", type=int)
ai.random_opening_depth = settings.value("random_opening_depth", ai.random_opening_depth, type=int)
ai.random_opening_options = settings.value("random_opening_options", ai.random_opening_options, type=int)
Expand Down Expand Up @@ -159,7 +162,7 @@ def to_settings(self, settings):
settings.setValue("moves_bound_low", self.moves_bound_low)
settings.setValue("moves_bound_high", self.moves_bound_high)
settings.setValue("use_positional_score", self.use_positional_score)
settings.setValue("use_timeout", self.use_timeout)
settings.setValue("use_timeout", self.deepening_within_timeout)
settings.setValue("timeout", self.timeout)
settings.setValue("random_opening_depth", self.random_opening_depth)
settings.setValue("random_opening_options", self.random_opening_options)
Expand Down Expand Up @@ -190,7 +193,8 @@ def params(self):
"moves_bound_low": self.moves_bound_low,
"moves_bound_high": self.moves_bound_high,
"use_positional_score": self.use_positional_score,
"time": self.timeout if self.use_timeout else None,
"time": self.timeout,
"deepening_within_timeout": self.deepening_within_timeout,
"random_opening_depth": self.random_opening_depth,
"random_opening_options": self.random_opening_options,

Expand Down
2 changes: 1 addition & 1 deletion python/hcheckers/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def make_item(value):
history = self.client.get_history()
if history is None:
return
self.setRowCount((len(history) / 2) + 2)
self.setRowCount((len(history) // 2) + 2)
row = 0
self.setItem(row, 0, make_item(_("Initial position")))
self.setItem(row, 1, make_item(_("Initial position")))
Expand Down
20 changes: 7 additions & 13 deletions python/hcheckers/settingsdlg.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,11 @@ def make_spinbox(title, low, high, tab):
layout.addRow(_("Use positional score"), self.use_positional_score)
self.use_positional_score.stateChanged.connect(self.edited)

self.use_timeout = QCheckBox(general)
layout.addRow(_("Continue thinking while there is time"), self.use_timeout)
self.use_timeout.stateChanged.connect(self.edited)
self.use_timeout.stateChanged.connect(self._on_use_timeout)
self.deepening_within_timeout = QCheckBox(general)
layout.addRow(_("Continue thinking while there is time"), self.deepening_within_timeout)
self.deepening_within_timeout.stateChanged.connect(self.edited)

self.timeout = make_spinbox(_("Timeout (seconds)"), 1, 120, general)
self.timeout.setEnabled(False)
self.timeout = make_spinbox(_("Timeout (milliseconds)"), 50, 120*1000, general)

self.random_opening_depth = make_spinbox(_("Random opening depth"), 1, 5, general)
self.random_opening_depth.setToolTip(_("Number of first moves to be considered as opening; during these moves, AI will select it's move randomly from several best options"))
Expand Down Expand Up @@ -172,10 +170,6 @@ def make_spinbox(title, low, high, tab):

self.setLayout(layout)

def _on_use_timeout(self):
use = self.use_timeout.checkState() == Qt.Checked
self.timeout.setEnabled(use)

def _on_save(self):
path, mask = QFileDialog.getSaveFileName(self, _("Save file"), ".", JSON_MASK)
if path:
Expand Down Expand Up @@ -209,8 +203,8 @@ def set_ai(self, ai):
self.moves_bound_low.setValue(ai.moves_bound_low)
self.moves_bound_high.setValue(ai.moves_bound_high)
self.use_positional_score.setCheckState(Qt.Checked if ai.use_positional_score else Qt.Unchecked)
self.use_timeout.setCheckState(Qt.Checked if ai.use_timeout else Qt.Unchecked)
self.timeout.setValue(1 if ai.timeout is None else ai.timeout)
self.deepening_within_timeout.setCheckState(Qt.Checked if ai.deepening_within_timeout else Qt.Unchecked)
self.timeout.setValue(AI.DEFAULT_TIMEOUT if ai.timeout is None else ai.timeout)
self.random_opening_depth.setValue(ai.random_opening_depth)
self.random_opening_options.setValue(ai.random_opening_options)

Expand Down Expand Up @@ -242,7 +236,7 @@ def get_ai(self):
ai.moves_bound_low = self.moves_bound_low.value()
ai.moves_bound_high = self.moves_bound_high.value()
ai.use_positional_score = self.use_positional_score.checkState() == Qt.Checked
ai.use_timeout = self.use_timeout.checkState() == Qt.Checked
ai.deepening_within_timeout = self.deepening_within_timeout.checkState() == Qt.Checked
ai.timeout = self.timeout.value()
ai.random_opening_depth = self.random_opening_depth.value()
ai.random_opening_options = self.random_opening_options.value()
Expand Down
2 changes: 1 addition & 1 deletion python/hcheckers/toplevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ def _splashscreen_size(self):
return screen_size / 2

def _show_splashcreen(self, message=None):
splash_size = self._splashscreen_size()
splash_size = int(self._splashscreen_size())
splash_pix = self._icon("splashscreen.svg").pixmap(QSize(splash_size, splash_size))
self.splashscreen = QSplashScreen(splash_pix, Qt.WindowStaysOnTopHint)
self.splashscreen.show()
Expand Down
Loading