Nantes Université

Skip to content
Extraits de code Groupes Projets
Valider 580dc509 rédigé par Naila TINSALHI's avatar Naila TINSALHI
Parcourir les fichiers

added better description of 'isFencePlacementPossible'

parent ee3c16e0
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
import { GameBoard } from "./game-board";
import { isValidPosition } from "./game-board";
import { Position, equals, bottom, right } from "./position";
import { Position } from "./position";
import * as positions from "./position";
import { getAdjacentPositions } from "./game-board";
import { Queue } from "./util";
import * as util from "./util"
import { Fence, getNumberSharedSquares, isHorizontal } from "./fence";
import { Square } from "./square";
import { isMovePossible } from "./movement-validation";
/**
......@@ -23,27 +21,37 @@ export function isFencePlacementPossible(gameBoard: GameBoard, start: Position,
#TODO: Implement this function
This function should check that:
- the positions start and stop are valid
- there is no intersection with other fences
- Whether the fence orientation is either vertical or horizontal.
- If the starting and ending positions of the fence are valid on
the game board.
- Whether the fence is within the boundaries of the game board.
- If placing the fence would intersect with any existing fences.
- Whether placing the fence would leave any pawn without a valid
path to reach their final position.
*/
return true;
}
/**
/**
* Checks if there exists a path between two positions on the game board.
*
* This function performs a breadth-first search (BFS) algorithm to determine if there is a valid path
* between two specified positions on the game board. It explores adjacent positions starting from the
* provided starting position until it reaches the target position or exhausts all possible paths.
*
* @param gameBoard The game board.
* @param start The starting position.
* @param target The target position.
* @returns True if a path exists between the positions, otherwise false.
*/
function existsPath(gameBoard: GameBoard, start: Position, target: Position): boolean {
function existsPath(gameBoard: GameBoard, start: Position, target: Position): boolean {
// Visited squares
const visited = new Array<Position>();
// Create a queue for BFS
const queue: Queue<Position> = util.queue<Position>() ;
const queue: Queue<Position> = util.queue<Position>();
util.enqueue(queue, start);
// BFS loop
......@@ -64,11 +72,10 @@ function existsPath(gameBoard: GameBoard, start: Position, target: Position): bo
&& isMovePossible(gameBoard, currentPos, adjPos)
&& !util.containsPosition(visited, adjPos)) {
// Enqueue adjacent position
util.enqueue(queue, adjPos);;
util.enqueue(queue, adjPos);
}
}
}
// No path found
return false;
}
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter