Skip to content

Instantly share code, notes, and snippets.

View deleteman's full-sized avatar

Fernando Doglio deleteman

View GitHub Profile
import React from 'react';
function App() {
return (
<Property1heroTablet
heroContainer="https://cdn.animaapp.com/projects/6202849b5e1915b58277544f/files/trailer-m-1-cut-1.webp"
title="SAM AWAY"
filmInfo="Adventure, Fantasy | 2019 | 136 Min."
filmAbout={
<React.Fragment>
// Define a function to display the grid and the nodeon the screen
function displayGrid(path) {
// Create a two-dimensional array to represent the grid
let grid = [];
for (let x = 0; x < width; x++) {
grid[x] = [];
for (let y = 0; y < height; y++) {
grid[x][y] = " . ";
}
}
function getPath(startX, startY, endX, endY) {
// Initialize an empty array to store the coordinates of the points on the path
let path = [];
// Use the Bresenham's line algorithm to get the coordinates of the points on the path
let x1 = startX, y1 = startY, x2 = endX, y2 = endY;
let isSteep = Math.abs(y2 - y1) > Math.abs(x2 - x1);
if (isSteep) {
[x1, y1] = [y1, x1];
[x2, y2] = [y2, x2];
function pathIntersectsObstacle(start, end, obstacles) {
// Convert the starting and ending coordinates to grid coordinates
let {x:startX, y:startY} = start;
let {x:endX, y:endY} = end;
// Get the coordinates of all points on the path
let path = getPath(startX, startY, endX, endY);
//get the points in the array that are within the list of obstacles
let instersections = path.filter( point => !!obstacles.find( o => o.x == point[0] && o.y == point[1]) ).length
function heuristic(state) {
// Calculate the number of steps required to reach the goal, using the Manhattan distance formula
let dx = Math.abs(state.x - goal.x);
let dy = Math.abs(state.y - goal.y);
let penalty = pathIntersectsObstacle(state, goal, obstacles) * 10
return Math.sqrt(dx*dx + dy * dy) + penalty;
}
function isObstacle(x, y) {
return obstacles.find( o => o.x == x && o.y == y)
}
let obstacles = [
{x:5,y:5, width: 1, height: 1},
{x:6,y:5, width: 1, height: 1},
{x:7,y:5, width: 1, height: 1},
{x:8,y:5, width: 1, height: 1},
]
// Define the function to generate the possible next steps from a given state
function generateNextSteps(state) {
// Define an array to store the next steps
let next = [];
// Check if the current state has any valid neighbors
if (state.x > 0) {
// If the current state has a neighbor to the left, add it to the array of next steps
if(!isObstacle(state.x - 1, state.y)) {
// Define the A* search function
function aStar(start, goal) {
// Create an empty data structure to store the explored paths
let explored = [];
// Create a data structure to store the paths that are being explored
let frontier = [{
state: start,
cost: 0,
// define a function to perform crossover between two individuals
const crossover = (individual1, individual2) => {
// choose a random crossover point
let point = Math.floor(Math.random() * NUM_CITIES);
// create the offspring by combining the two individuals
let offspring = individual1.slice(0, point).concat(individual2.slice(point));
// return the offspring
return offspring;
};