From ec52e565f779f93f069cca2bd0bce9027a5fcf77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=BCnther?= Date: Sun, 28 Mar 2010 23:16:45 +0200 Subject: Added method Pos::interacts_with --- HISTORY | 1 + puzzle.cpp | 7 +++---- puzzle.h | 4 +++- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/HISTORY b/HISTORY index 81dee19..19513d0 100644 --- a/HISTORY +++ b/HISTORY @@ -92,3 +92,4 @@ ____-__-__: Version 0.3.5 - Changed repository from subversion to git. - Removed subversion keywords ($Id). - Added support for VDR >= 1.7.13 (Make.global). +- Added method Pos::interacts_with. diff --git a/puzzle.cpp b/puzzle.cpp index 120db9e..3571d39 100644 --- a/puzzle.cpp +++ b/puzzle.cpp @@ -1,7 +1,7 @@ /* * Sudoku: A plug-in for the Video Disk Recorder * - * Copyright (C) 2005-2008, Thomas Günther + * Copyright (C) 2005-2010, Thomas Günther * * 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 @@ -196,7 +196,7 @@ void Puzzle::set(Pos pos, unsigned int number) // Refresh possible numbers of all affected cells. for (Pos p = Pos::first(); p <= Pos::last(); p = p.next()) - if (p.col() == pos.col() || p.row() == pos.row() || p.reg() == pos.reg()) + if (p.interacts_with(pos)) compute_numbers(p); } } @@ -362,8 +362,7 @@ void Puzzle::compute_numbers(Pos pos) // Disable numbers found in row, column or region. for (Pos p = Pos::first(); p <= Pos::last(); p = p.next()) - if (p != pos && - (p.col() == pos.col() || p.row() == pos.row() || p.reg() == pos.reg())) + if (p.interacts_with(pos)) numbers[pos][get(p)] = false; // Count the possible numbers. diff --git a/puzzle.h b/puzzle.h index ad47cf1..3bc6feb 100644 --- a/puzzle.h +++ b/puzzle.h @@ -1,7 +1,7 @@ /* * Sudoku: A plug-in for the Video Disk Recorder * - * Copyright (C) 2005-2008, Thomas Günther + * Copyright (C) 2005-2010, Thomas Günther * * 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 @@ -71,6 +71,8 @@ namespace Sudoku Pos next_col() const { return col() < DIM-1 ? pos + 1 : pos; } Pos prev_row() const { return row() > 0 ? pos - DIM : pos; } Pos next_row() const { return row() < DIM-1 ? pos + DIM : pos; } + bool interacts_with(Pos other) const { return pos != other && + (col() == other.col() || row() == other.row() || reg() == other.reg()); } }; -- cgit v1.2.3