An Ai Game That Solve The problem of finding the correct path from source to destination

Overview

Monkey And Banana AI Game

  • An Ai Game That Solve The problem of finding the correct path from source to destination .

  • Use BeathFirst Algorithm.


Game Apk Link To Download and Install


Game Video on youtube


Explain How Game Play :

  • the monkey find four paths to banana .
  • he go in every path and check is the banana there in the end or what
  • if it there he win otherwise he go in the next path .....
  • the goal or the location of banana is random .

Image of Yaktocat


Implementation The Project (Some Important Code ) :-

We Work With Flutter .

  • At First : We use graph to design the Ui and we consider the game as group of nodes and edges then by using BreathFirst Algorithm We Search for The Random Goal (Banana) using Iterator in Dart .

  • _BreadthFirstTree creates the BreadthFirstIterator. Also, both of these collections stores the Graph object to save the tree data structure itself.

ITreeIterator defines a common interface for all specific iterators of the tree collection:

  • hasNext() - returns true if the iterator did not reach the end of the collection yet, otherwise false;
  • getNext() - returns the next value of the collection;
  • reset() - resets the iterator and sets the current position of it to the beginning.

the breadth-first algorithm uses the Queue data structure

to store nodes (vertices) which should be visited next .


Graph Code In Dart

A class which stores the adjacency list of the graph. It is stored as a map data structure where the key represents the node's (vertix) id and the value is a list of vertices (ids of other nodes) adjacent to the vertex of that id (key). Also, this class defines the addEdge() method to add an edge to the adjacency list.

class Graph {
  final Map> adjacencyList = Map>();

  void addEdge(int source, int target) {
    if (adjacencyList.containsKey(source)) {
      adjacencyList[source].add(target);
    } else {
      adjacencyList[source] = {target};
    }
  }
}

Tree collections

  • BreadthFirstTreeCollection - a tree collection class which stores the graph object and implements the createIterator() method to create an iterator which uses the breadth-first algorithm to traverse the graph.
class BreadthFirstTreeCollection implements ITreeCollection {
  final Graph graph;

  const BreadthFirstTreeCollection(this.graph);

  @override
  ITreeIterator createIterator() {
    return BreadthFirstIterator(this);
  }

  @override
  String getTitle() {
    return 'Breadth-first';
  }
}

BreadthFirst Algorithm code :-

  • BreadthFirstIterator - a specific implementation of the tree iterator which traverses the tree collection by using the breadth-first algorithm. This algorithm uses the queue data structure to store vertices (nodes) which should be visited next using the getNext() method.
class BreadthFirstIterator implements ITreeIterator {
  final BreadthFirstTreeCollection treeCollection;
  final Set visitedNodes = {};
  final ListQueue nodeQueue = ListQueue();

  final int _initialNode = 1;
  int _currentNode;

  BreadthFirstIterator(this.treeCollection) {
    _currentNode = _initialNode;
    nodeQueue.add(_initialNode);
  }

  Map> get adjacencyList => treeCollection.graph.adjacencyList;

  @override
  bool hasNext() {
    return nodeQueue.isNotEmpty;
  }

  @override
  int getNext() {
    if (!hasNext()) {
      return null;
    }

    _currentNode = nodeQueue.removeFirst();
    visitedNodes.add(_currentNode);

    if (adjacencyList.containsKey(_currentNode)) {
      for (var node in adjacencyList[_currentNode]
          .where((n) => !visitedNodes.contains(n))) {
        nodeQueue.addLast(node);
      }
    }

    return _currentNode;
  }

  @override
  void reset() {
    _currentNode = _initialNode;
    visitedNodes.clear();
    nodeQueue.clear();
    nodeQueue.add(_initialNode);
  }
}

Grraph (Ndes & Edges) defenition :

  Graph _buildGraph() {
    var graph = Graph();

    graph.addEdge(1, 21);
    graph.addEdge(1, 22);
    graph.addEdge(1, 23);
    graph.addEdge(1, 24);

    graph.addEdge(21, 31);
    graph.addEdge(21, 25);
    graph.addEdge(21, 20);
    graph.addEdge(21, 14);
    graph.addEdge(21, 13);
    graph.addEdge(21, 7);
    graph.addEdge(21, 11);
    graph.addEdge(21, 28);
    ....
    ....
    ....
    ....
    return graph;
  }

you will find the code of Implementation in (lib) Folder

You might also like...

changelog.dart provides a library and a command-line application to manage in the correct way the git metadata to build the changelog between two release

changelog.dart provides a library and a command-line application to manage in the correct way the git metadata to build the changelog between two release

changelog.dart 🎯 changelog.dart: a collection of tools to manages in a fashion way a repository as maintainer. 🎯 Project Homepage Table of Content I

Dec 18, 2022

🎨 An opinionated, effective and correct way to provide multiple themes to your app.

🎨 An opinionated, effective and correct way to provide multiple themes to your app.

theming This is an opinionated and effective way to provide multi-theme choice for your app. theming depends on provider and shared_preference for sta

Nov 28, 2022

Tap Hero Game - An Open Source Flutter Game

Tap Hero Game - An Open Source Flutter Game

Tap Hero 📱 🎮 TapHero is a casual tapping arcade game. This repo includes Android, iOS, Desktop (macOS, Windows, Linux). For Flutter Web, check the T

Dec 19, 2022

Flutter video compress - Generate a new file by compressed video, and provide metadata. Get video thumbnail from a video path, supports JPEG/GIF. To reduce app size not using FFmpeg in IOS.

Flutter video compress - Generate a new file by compressed video, and provide metadata. Get video thumbnail from a video path, supports JPEG/GIF. To reduce app size not using FFmpeg in IOS.

flutter_video_compress Generate a new path by compressed video, Choose to keep the source video or delete it by a parameter. Get video thumbnail from

Dec 8, 2022

Rock-Paper-Scissor-Game-Using-Dart - This is a repository of Rock Paper Scissor Game which I developed while learning Dart.

Rock-Paper-Scissor-Game-Using-Dart This is a repository of Rock Paper Scissor Game which I developed while learning Dart. The main.dart file consist o

Jan 4, 2022

Video game ui - Video Game App UI In Flutter!

video_game_ui A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started if

Sep 6, 2022

Color matching game - A Crossplatform Color Matching Game made with Flutter

Color matching game - A Crossplatform Color Matching Game made with Flutter

color_matching_game A Color Matching Game built with Flutter. It is a simple app made without adding a plug-in. Play by specifying the red, green and

Nov 21, 2022

An Open Source Todo App Built with Flutter

An Open Source Todo App Built with Flutter

taskit Not Just Another Todo App. P.S: An App build to test the features of Flutter and will continue to update as the world of flutter expands along

Oct 9, 2022

An open source flutter ride-hailing app for learning purpose(Provider & Bloc)

citycab An open source ride hailing app with flutter. Getting Started This project is a starting point for a Flutter application. A few resources to g

Jan 2, 2023
Owner
null
Numbers is simple game to improve problem solving skills and it is built in Flutter Framework

Numbers - Flutter Game Numbers is a simple game built in Flutter Framework and is purely based on numbers to improve problem solving skills. Screensho

Thamaraiselvam 49 Oct 21, 2022
A Flutter application about finding a specific person for a job you're looking for to hire

flutter_app2 A new Flutter application. Getting Started This project is a starting point for a Flutter application. A few resources to get you started

Niyaz Irfan 1 Dec 16, 2021
Mobile - Budipest - A community-based toilet finder app that seeks to alleviate the problem of public toilets in Hungary

Budipest | App Store | Google Play | Facebook What's the deal with the name? Bud

Budipest 2 Feb 7, 2022
An Application for solving the problem of Postmartum Depression.

Our app Dear Canary solves the problem of Postpartum depression. We ask the user to answer some basic questions based on which we provide them an analysis of their PPD level. After the problem has been recognized they can have access to a community of people with similar issues. They can write diaries to calm their mind and many more good features such like that.

Abhay K. Mittal 5 May 27, 2022
TheMathU Similarity Index App will accept a mathematical problem as user input and return a list of similar problems that have memorandums.

Technologies MathU Similarity Index - Segmentation Cult The MathU Similarity Index App accepts a mathematical problem as user input and returns a list

COS 301 - 2022 7 Nov 2, 2022
A new Flutter project for finding movie and its details

movie_finder A new Flutter project for finding movie and its details. Project Screenshots Home Page Movie Detail Page #Project pages Home Page - Done

ZR Shamim 3 May 22, 2022
DigHub is a GitHub client to help you finding intresting projects

dighub DigHub is a GitHub client to help you finding intresting projects. It's based on the GitHub API's events interface, which gives you real-time a

Maxiee 51 Dec 30, 2022
Flutter package to get keyboard height. Can be used to display a sticker/emoji modal with correct height.

flutter_persistent_keyboard_height Flutter package to get keyboard height. The height is persisted during app sessions and keyboard states (you can us

Arshak Aghakaryan 13 Oct 17, 2022
This application was created using the Dart language and it is an application that contains a set of different questions and at the end shows you the number of correct answers you have answered , made by flutter

exams_app A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started if thi

null 0 Dec 28, 2021
Flutter bloc infinite list - A sample application to learn flutter bloc the correct way

flutter_bloc_infinite_list A sample application to learn flutter bloc the correc

Anoop TM 2 Aug 22, 2022