Skip to content

Instantly share code, notes, and snippets.

View esshka's full-sized avatar
🏠
Working from home

Eugeny esshka

🏠
Working from home
View GitHub Profile
@esshka
esshka / snake.js
Created October 20, 2023 19:33
snake game state
import { makeAutoObservable } from 'mobx';
class SnakeGameStore {
// Defining the game grid size
gridSize = 10;
// Defining the snake's initial position and direction
snake = [{ x: 5, y: 5 }];
direction = { x: 0, y: 1 }; // Starts moving downwards
@esshka
esshka / neat.js
Created September 7, 2023 17:53
NEAT
class Node {
id
value = 0.0
type
constructor(id, type) {
this.id = id
this.type = type
(defn is-merge [s part1 part2]
(let [s-len (count s)
p1-len (count part1)
p2-len (count part2)]
(if (> s-len (+ p1-len p2-len))
false
(loop [s-idx 0
p1-idx 0
p2-idx 0]
(if (= s-idx s-len)
function compatibilityDistance(network1, network2, c1 = 1, c2 = 1, c3 = 0.4) {
const i1 = new Set(network1.connections.map((c) => c.innovation));
const i2 = new Set(network2.connections.map((c) => c.innovation));
const disjoint =
[...i1].filter((i) => !i1.has(i)).length +
[...i2].filter((i) => !i2.has(i)).length;
const excess = Math.max(i1.size, i2.size) - Math.min(i1.size, i2.size);
const matching = network1.connections.filter((c1) => i2.has(c1.innovation));
function calculateFitness(network, data) {
let fitness = 0;
for (const { input, output } of data) {
const prediction = network.propagate(input);
const error = output[0] - prediction[0];
fitness += 1 - Math.abs(error * error);
}
// Normalize the fitness value by dividing it by the number of data points
return fitness / data.length;
}
const learningRate = 0.3;
class Sigmoid {
static calculate(x) {
return 1 / (1 + Math.exp(-x));
}
static derivative(x) {
const fx = Sigmoid.calculate(x);
return fx * (1 - fx);
function getPINs(observed) {
// TODO: This is your job, detective!
function flatten(array)
{
if(array.length == 0)
return array;
else if(Array.isArray(array[0]))
return flatten(array[0]).concat(flatten(array.slice(1)));
else
const ErrorsContainer = ({errors}) => {
if (errors.length === 0) {
return null;
}
return errors.map(err => {
if (err.displayType === MODAL_ERROR_DISPLAY_TYPE) {
return <ModalError error={err} key={Math.random()} />;
}
React.isValidElement(Component())
String(component).includes('return React.createElement')
@esshka
esshka / test.js
Created July 15, 2018 14:28 — forked from tsur/test.js
serialize/deserialize es6 class
class MyChart {
constructor(){
this.foo = "foo";
return this;
}
sayFoo(){