Refactor with a Position2d struct

This commit is contained in:
2023-02-10 20:32:56 +01:00
parent 2b4ef27f92
commit e67a28d110
4 changed files with 169 additions and 18 deletions

View File

@@ -2,6 +2,7 @@ use crate::board::Board;
use crate::lexer::lexer;
use crate::parser;
use crate::parser::{Expression, Expressions};
use crate::position::Position2d;
use crate::tile::{Operator, Tile};
pub fn calculate(expr: &Expression) -> f64 {
@@ -36,10 +37,10 @@ pub fn are_valid_expressions(expr: &Expressions) -> bool {
res.is_some()
}
pub fn is_valid_guess(board: &Board, positions: &[(usize, usize)]) -> Result<bool, ()> {
pub fn is_valid_guess(board: &Board, positions: &[Position2d]) -> Result<bool, ()> {
let tiles = positions
.iter()
.map(|&(x, y)| board.get(x, y))
.map(|&pos| board.get(pos.x, pos.y))
.collect::<Option<Vec<Tile>>>()
.ok_or(())?;