Coder Social home page Coder Social logo

fastway's Introduction

como funciona

O algoritmo escolhe uma posição estável para passar, caso a trajetória dê errado, ela volta para trás e começa tudo de novo até achar a posição estável, se não achar, ela volta para trás novamente e assim em diante até achar a posição certa que leva para o final do labirinto

o algoritmo foi pensado para calcular a trajetória de um labirinto. Mas ele pode ser usado em outros casos, como calcular a trajetória de um lugar para o outro

uso com arquivo

#include "fastway.h"
#include <iostream>

int main() {
  std::vector<std::vector<int>> result = FastWay::run("labirinto.txt");
  
  components::print(result); //imprime o vetor bidimensional
  
  return 0;
}

estrutura do labirinto em arquivo

2,1,1,1,1
0,0,0,0,1
1,1,1,1,1
0,0,1,0,0
3,1,1,1,1

Códigos:
2 : inicio do labirinto
0 : parede/trilha que não pode passar
1 : trilha
3 : final do labirinto
4 : trilha percorrida
5 : posição atual (usada somente no callback)

usando vetores

#include "fastway.h"
#include <iostream>

int main() {
  std::vector<std::vector<int>> labirinto = {
   {2,1,1,1,1},
   {0,0,0,0,1},
   {1,1,1,1,1},
   {0,0,1,0,1},
   {3,1,1,1,1}
  };
  
  std::vector<std::vector<int>> result = FastWay::run(labirinto);
  
  components::print(result); //imprime o vetor bidimensional
  
  return 0;
}

Saída

2 4 4 4 4
0 0 0 0 4
1 1 4 4 4
0 0 4 0 1
3 4 4 1 1

callbacks ???

Sim. Seu uso não é obrigatório, mas isso irá deixar o terminal mais legal podendo visualizar cada ação do algoritmo sobre o labirinto.

#include "src/fastway.h"
#include <iostream>
#include <unistd.h>

using namespace std;

// Estrutura padrão da função
void func(std::vector<std::vector<int>> lab){
   int seg=1;
   system("clear");

   FastWay::print(lab, true); // imprime o labirinto em forma colorida.

   usleep(seg*100*1000);
}

int main() {
	vector<vector<int>> res = FastWay::run("file.txt", func); // imprime o labirinto e retorna um callback a cada ação.
	printf("\n");
	FastWay::print(res); // imprime o labirinto.

	return 0;
}

fastway's People

Contributors

unbreak4ble avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.