Skip to content

yakov103/Ex4_OOP

 
 

Repository files navigation

Ex4 OOP Ariel Univercity ✨

image

after implementing graphs algorithm's:

  • TSP()
  • ShortestPath()
  • Center()

now we made a game out of it 🕹

Run Locally

Clone the project

  git clone https://github.com/dolev146/Ex4_OOP.git

Go to the project directory

  cd Ex4_OOP

Install dependencies

  pip install -r requirements.txt

Start the server make sure you have java installed case 0 - 15 , the number in the end of the line is the case number

     java -jar Ex4_Server_v0.0.jar 0

and on a diffrent terminal

  cd Ex4_OOP
windows
    python Ex4.py

mac
    python3 Ex4.py

Gui Demo

press the image to go to the video

IMAGE ALT TEXT HERE

Thought planning and execution

First we had to choose a language, we chose Python because it was faster to develop in Python than in Jaba a lesson we learned from previous assignments, however we had to do more sessions to understand what to do and what variables are going through, i.e. to strengthen communication. At the beginning of the task we had to think about what format to work in, and how in general the information flows in the software, how to access it, what names we call variables and cause uncertainty to become absolute certainty of a form of work. After we created a working skeleton of the software, we divided the task between us each what he does best. Yakov did the part of the algorithm, Daniel worked on the position of the Pokemon and a function that prevents the number of calls to move to go through the 10 times per second and on the display, Dolev worked on the combination of information between the two things so that they do not collide. And finally we managed to get to something that works well in a relatively short time. also python got us better resolts in the time comparison

design patterns used

image

  • MVC - we seperated the calculation of the data from the importing and exporting the data from the server functions so that a function that run an algoritm only take care of calculation , and a function that deals with server only take care interacting with the server. inspired from React by using a single source of truth.
  • singleton - we used a singelton + state design patterns so that all the code is referencing one specific objects that are located in the file settings.py and in every use of them you need to import them to use them.

Unit Tests

inside file Ex4Test.py

image

image

Algorithms functions

  • make_decisions() - This function detects when the agent has reached the position he needs, calculates the next step and adds it to settings.move_list settings.move_list.append({"agent_id": agent.id , "next_node_id": next_node) *** note it will only add a move list when it is not exist we chose the aproach of using greedy algorithm, that sends the agents to the closest pokemon by using the tsp function we made in ex3 to compare the pokemons and choose the agents paths

  • pokemon.set_edge() - tell me where is the pokimon located on which edge so that we can tell what is the node we need to go in order the catch the pokemon.

Authors

Ex3 OOP Ariel Univercity

image

the project is about implementing graphs algorithm's:

  • TSP()
  • ShortestPath()
  • Center()

The software also has a gui to give easier use.

Run Locally

Clone the project

  git clone https://github.com/dolev146/Ex3.git

Go to the project directory

  cd Ex3

Install dependencies

  pip install -r requirements.txt

Start the Gui

windows
    python Ex4.py ./data_ex3/A0.json

mac
    python3 Ex4.py ./data_ex3/A0.json

please watch the demo to know the specific input sytax.

Gui Demo

image image image to use the tsp input box for example you will need to

  • insert the id numbers of the node seperated by comma (' , ')
  • press the Return button on the keyboard AKA Enter button

watch the YouTube video explaining everything IMAGE ALT TEXT HERE

Test our code

image

just follow the instructions in the Ex3.py , how to disable the gui and print the results you wish to check

Lessons Learned

we learned to work as a team with git and github. we learend that in order to work better we first need to to plan before we start writing the code.

Unit Tests

iside the Tests directory you can see all the tests

image

image

RunTime compare

image and took the result from the terminal for example:

image

comapre vs python table
image image
image image
image image
image image
image image

image windows 10 pro

data structure

the Graph captures the data in 4 Dictionaries .

  • dictionary for the nodes - implementing editing nodes by their id in O(1)
  • dictionary for the edges - implementing editing edges by taking the sourse and destantion of the edge, and convert it to 1 string (src_dest) key that gives us the edge on O(1) and 2 other dictionaries for in and out edges.

implemented classes

  • CNode - Node of graph.
  • CEdge - Edges of graph.
  • DiGraph - implementing GraphInterface
  • GraphAlgo - implementing GraphAlgoInterface

Algorithms functions

  • center - This functions return the Node Id that in the center of the graph (relative to the rest of the vertices) and his distance.In this function we use the dijkstra algorithm to caculte the length from node to the other nodes and this help us to find the center node(vertex).

  • tsp - This function get list of nodes(vertex) Id's and return list of nodes Id's that present the path that pass in the nodes that we get and the overall distance,also the function return "good" path and not path that pass to mach vertex and visit vertex that not necessaries .We use shortest_path function to find the best path from node to node.

  • shortestPath - This function get src and dest Id and return Node list of all the Nodes Id's that in the shortest path in the same order as they show up in the path.

  • Plot graph - This function search in the init graph empty nodes and fill them with random cordinates depending on the scale : If the graph is made from empty nodes , the scale will be automatic else, the function will find the min and max nodes in the graph to get the scaling , and combined them . If there is only 1 node in the graph with cordinates, the other new random nodes will be around him .

classes functions

CEdge class functions

  • src
  • dest
  • w
  • info

CNode class functions

  • id
  • info
  • previous
  • length
  • rank
  • x
  • y
  • z

DiGraph (implements Graph interface) class functions

  • v_size
  • e_size
  • get_all_v
  • all_in_edges_of_node
  • all_out_edges_of_node()
  • get_mc()
  • add_edge(int node_id)
  • add_node(int node_id)
  • remove_node
  • remove_edge

GraphAlgo (implements GraphAlgoInterface) class functions

  • init
  • get_graph
  • shortest_path
  • centerPoint
  • TSP
  • Plot graph
  • save_to_json
  • load_from_json

UML

new image

Authors

About

Pokemon Game

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%