Skip to content

Instantly share code, notes, and snippets.

View ahmedfgad's full-sized avatar

Ahmed Gad ahmedfgad

View GitHub Profile
@ahmedfgad
ahmedfgad / flask_app.py
Created April 12, 2023 16:04
Minimal Flask application for testing.
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello, World!'
app.run(host="0.0.0.0", port="8000")
@ahmedfgad
ahmedfgad / gist:2601f1d5ef8c274a391cbfee230e5f5d
Created October 3, 2021 21:15
Thread to Run PyGAD in the Background // Play the Flappy Bird Game using PyGAD
import pygad
import threading
class PygadThread(threading.Thread):
def __init__(self):
super().__init__()
def run(self):
ga_instance = pygad.GA(num_generations=200000,
@ahmedfgad
ahmedfgad / Flappy_Bird_PyGAD_02.py
Created October 3, 2021 21:14
Fitness Function of the Bot Playing the Flappy Bird Game using PyGAD
def fitness_func(solution, solution_idx):
global SCREEN, playery, pipeHeight, playerx, upperPipes, lowerPipes, GAME_SPRITES, playerVelY, playerFlapAccv, playerFlapped, playerMaxVelY, playerAccY, playerHeight, GROUNDY, nearest_upper_pipe, nearest_lower_pipe
if solution < 0:
return -8888
if solution > GROUNDY - 25:
return -9999
fitness_ground = abs(solution - GROUNDY)
@ahmedfgad
ahmedfgad / Flappy_Bird_PyGAD_01.py
Created October 3, 2021 21:07
Play the Flappy Bird Game using PyGAD
import random # For generating random numbers
import sys # We will use sys.exit to exit the program
import pygame
from pygame.locals import * # Basic pygame imports
import pygad
import threading
class PygadThread(threading.Thread):
import socket
import pickle
import numpy
import pygad
import nn
import gann
import kivy.app
import kivy.uix.button
import socket
import pickle
import numpy
import threading
import pygad
import nn
import gann
class RecvThread(threading.Thread):
import kivy.app
import kivy.uix.button
import kivy.uix.label
import kivy.uix.boxlayout
import kivy.uix.textinput
import threading
class ClientApp(kivy.app.App):
class ClientApp(kivy.app.App):
def build(self):
self.create_socket_btn = kivy.uix.button.Button(text="Create Socket")
self.server_ip = kivy.uix.textinput.TextInput(hint_text="Server IPv4 Address", text="localhost")
self.server_port = kivy.uix.textinput.TextInput(hint_text="Server Port Number", text="10000")
self.server_info_boxlayout = kivy.uix.boxlayout.BoxLayout(orientation="horizontal")
self.server_info_boxlayout.add_widget(self.server_ip)
import socket
import pickle
import threading
import time
import numpy
import nn
import gann
import kivy.app
import socket
import pickle
import time
import numpy
import nn
import gann
class SocketThread(threading.Thread):