Playing Gomoku with minimax alpha-beta pruning algorithm
Program developed in Java as part of the AI module at Queen Mary University of London.
Solution built reached 4th place in the class competition of 100+ students.
GUI for the game was already provided.
To play against it run java GomokuReferee and select Player.
Instructions:
Two players (white and black) take turns at placing a stone of his/her colour on an unoccupied square on the board (white moves first). The first player to complete a continuous horizontal, vertical or diagonal line of 5 or more stones of his/her colour is the winner (scoring 2 points). The loser scores 0. If all squares are occupied and neither player has won, then each player gets 1 point.
Restrictions:
Time limit of 10 seconds per move. Any program which exceeds this limit will immediately forfeit the game to its opponent.
Similarly any program which raises an exception or makes an illegal move (out of range or already occupied) will lose immediately. There are no other restrictions on moves (gomoku experts may be aware that some tournaments have further restrictions).
See Example to get started quickly.
To run the example project, clone the repo, and run pod install.
Then add next capability`s to your app target:
– Personal VPN
– Network Extensions (Packet Tunnel, App Proxy)
import CoreVPN
class ViewController: UIViewController {
var corevpn: CoreVPN!
override func viewDidLoad() {
super.viewDidLoad()
self.corevpn = CoreVPN(serviceName: "Name_of_your_vpn (you will see that name in settings)", servers: corevpnServers, delegate: self)
}
@IBAction func connect(_ sender: UIButton) {
corevpn.connect()
}
@IBAction func disconnect(_ sender: UIButton) {
corevpn.disconnect()
}
@IBAction func chooseOptimalLocation(_ sender: UIButton) {
corevpn.getOptimalServer { server in
// select best server based on ping
self.corevpn.selectServer(server: server)
}
}
@IBAction func chooseRandomLocation(_ sender: UIButton) {
if let server = corevpnServers.randomElement() {
// select server you need
corevpn.selectServer(server: server)
}
}
}
And Delegate methods
extension ViewController: CoreVPNDelegate {
func serverChanged(server: CoreVPNServerModel) {
// update view or make smth you need
}
func connenctionTimeChanged(time: String) {
// update view or make smth you need
}
func connectionStateChanged(state: CoreVPNConnectionState) {
// update view or make smth you need
}
}
Requirements
iOS >= 9.0
Installation
CoreVPN is available through CocoaPods. To install
it, simply add the following line to your Podfile:
This project is meant for personal use.
I won’t stop you from using it, but I would rather recommend to use a similar
and more mature solution like jotai.
// ReadconstcurrentValue=myAtom.get(atom);// WritemyAtom.set(nextValue);// Subscribe to changesmyAtom.subscribe((value)=>{console.log(value);});
Usage examples
Vanilla typescript
import{createAtom,CONFIG,localStorage}from"@yaasl/core";// Provide an app name to yaaslCONFIG.name="demo-vanilla";// Create a counter atom that is connected to the local storageconstcounter=createAtom({name: "counter",// local storage key will be "demo-vanilla/counter"defaultValue: 0,effects: [localStorage()],});constsetupCounter=(element: HTMLButtonElement)=>{constupdateCounterText=(value: number)=>(element.innerHTML=`count is ${value}`);element.addEventListener("click",()=>{// Set the value of the atomcounter.set((previous)=>previous+1);});// Subscribe to value changescounter.subscribe((value)=>updateCounterText(value));// Read the value of the atom in the storeupdateCounterText(counter.get());};constcounter=document.getElementById("counter");setupCounter(counter);
React (or Preact)
import{createAtom,CONFIG,localStorage,useAtom}from"@yaasl/react";// or "@yaasl/preact"// Provide an app name to yaaslCONFIG.name="demo-react";// Create a counter atom that is connected to the local storageconstcounter=createAtom({name: "counter",// local storage key will be "demo-react/counter"defaultValue: 0,effects: [localStorage()],});exportconstCounter=()=>{// Use the atom like you would use a stateconst[value,setValue]=useAtom(counter);constonClick=()=>setValue((previous)=>previous+1);return<buttononClick={onClick}>count is {value}</button>;};
This project is meant for personal use.
I won’t stop you from using it, but I would rather recommend to use a similar
and more mature solution like jotai.
// ReadconstcurrentValue=myAtom.get(atom);// WritemyAtom.set(nextValue);// Subscribe to changesmyAtom.subscribe((value)=>{console.log(value);});
Usage examples
Vanilla typescript
import{createAtom,CONFIG,localStorage}from"@yaasl/core";// Provide an app name to yaaslCONFIG.name="demo-vanilla";// Create a counter atom that is connected to the local storageconstcounter=createAtom({name: "counter",// local storage key will be "demo-vanilla/counter"defaultValue: 0,effects: [localStorage()],});constsetupCounter=(element: HTMLButtonElement)=>{constupdateCounterText=(value: number)=>(element.innerHTML=`count is ${value}`);element.addEventListener("click",()=>{// Set the value of the atomcounter.set((previous)=>previous+1);});// Subscribe to value changescounter.subscribe((value)=>updateCounterText(value));// Read the value of the atom in the storeupdateCounterText(counter.get());};constcounter=document.getElementById("counter");setupCounter(counter);
React (or Preact)
import{createAtom,CONFIG,localStorage,useAtom}from"@yaasl/react";// or "@yaasl/preact"// Provide an app name to yaaslCONFIG.name="demo-react";// Create a counter atom that is connected to the local storageconstcounter=createAtom({name: "counter",// local storage key will be "demo-react/counter"defaultValue: 0,effects: [localStorage()],});exportconstCounter=()=>{// Use the atom like you would use a stateconst[value,setValue]=useAtom(counter);constonClick=()=>setValue((previous)=>previous+1);return<buttononClick={onClick}>count is {value}</button>;};
1. mongoDB:
1.1. create user + password <password> - https://account.mongodb.com/account/login
1.2. login to mongo atlas
1.3. create DB <dbname> (cluster->collection->create db btn)
1.4. create collection name:"products"
1.5. copy your connection string from:
- right menu -> click "Cluster" -> click "connect" btn -> popup will open
- click "connect with your application" -> copy the "const uri = ...."
- uri need to be like this: const uri = "mongodb+srv://linoravny:<password>@cluster0.ps0o2.azure.mongodb.net/<dbname>?retryWrites=true&w=majority";
- <password> => change to your passweord , <dbname> - the db name that you create in section 1.2.
2. this project
2.1. open server.js file
2.2. change the uri to your copy uri from section 1.5
2.3. open cmd in the root
2.4. run -> $ npm install
run project
server node JS in the root
- $ npm run start; (http://localhost:3000/)
desctopVanilla client
- run index.html in desktopVanilla/index.html (right click on index html + copy path -> then run in chrome)
angular
only first time -> $ npm install; for install node_modules folder
This package hosts an array of frequently used regex validations and regex expression evaluation functionalities. In general, String check encompasses last word check, middle word check, first word check, sentence validation, phone number validation, name validation with or without honorific, password with both default parameter settings and custom parameter settings, hexadecimal string validation,alphanumeric string validation and binary string validations. Expression resolving encompasses conversions like infix to postfix and infix to prefix, and evaluation compasses java equation solving and resultant equation output.
The package makes use of intense regex expressions for peak validation under default settings. SimpleCipher is highly useful for developers who are in need for rapid and accurate FORM VALIDATIONS
that are available over both the Web, Android and Javascript.
Name validation:
According to javadoc,
/**
This function validates if a string is valid a valid name. The
honorific is allowed if user defined.
@param name String that needs to be validated.
@param checkHonorific True if name includes a honorific else false.
@param isAllUpperCase True is all the letters are in uppercase, else
false. Then it checks if the first letter of every starting word is in
uppercase.
@return True if the String is a valid word, else false.
*/
Allows developers to decide their own password restriction parameters. First create an object of CustomPasswordFilter with desired precision parameters. For example,
This returns only true or false based on userInputPassword match, however developers may want to let their user know of individual field validation by creating progress dialog box that ticks off the validated fields.
To allow such parametric validations, developers can use function isCustomPasswordParametric(userInputPassword, CustomPasswordFilter), that returns a boolean array of size 5. The index definitions are as follows:
Index 0 – Alphabet validation along with minimum alphabet length check.
Index 1 – Digit validation along with minimum digit length check.
Index 2 – Symbol validation along with minimum symbol length check.
Index 3 – Total minimum length check.
Index 4 – Total maximum length check.
For in depth and better explanation refer to javadoc.
Expression Evaluation:
The sub package Expressions is responsible for evaluating expressions.
For example, say we want to solve an expression 10 + ( 2 * 5 ).
Then the equivalent code shall be as follows,
Double result=SimpleCipher.Expressions.Evaluation.solveEq(“(,10,+,(,2,*,5,),)”);
For in depth and better explanation refer to javadoc.
OLX.com.pk is a prominent online classifieds platform serving as a versatile marketplace for a wide range of goods and services in Pakistan. It has gained immense popularity as a go-to destination for both buyers and sellers to post and find classified advertisements. OLX offers a comprehensive spectrum of categories, including real estate, automobiles, electronics, home and garden, fashion, and services. The platform allows users to connect, trade, and engage in transactions for various items and services.
Data Analysis and Visualization:
Subsequent to the successful web scraping activities on OLX.com.pk, you utilized data analysis and visualization tools to make sense of the collected data. Such tools are instrumental in exploring and interpreting the scraped data, enabling you to generate insightful data visualizations and analytics.
Potential Insights and Applications:
Through your web scraping and data analysis endeavours on OLX.com.pk, you can potentially unearth valuable insights about the e-commerce and classifieds market in Pakistan. These insights could be leveraged by consumers to make informed purchase decisions, by sellers to create more effective listings, or by market analysts to gain a deeper understanding of consumer preferences and market trends in the Pakistani e-commerce sector.
#!/usr/bin/env sh
cat autovshard_cfg.yaml | consul kv put "autovshard/mycluster/autovshard_cfg_yaml" -
Autovshard Consul config parameters
The config is similar to Vshard config, but it has some extra fields
and has address field instead of uri because we don’t want to
mix config with passwords.
master_weight – an instance with higher weight in a replica set eventually gets master role. This parameter is dynamic and can be changed by administrator at any time. The number is used only for comparison with the master_weights of the other members of a replica set.
switchover_delay – a delay in seconds to wait before taking master role away from another running instance with lower master_weight. This parameter is dynamic and can be changed by administrator at any time. A case when this parameter is useful is when an instance with the highest master_weight is restarted several times in a short amount of time. If the instance is up for a shorter time than the switchover_delay there will be no master switch (switchover) every time the instance is restarted. And when the instance with the highest master_weight stays up for longer than the switchover_delay then the instance will finally get promoted to master role.
address – TCP address of the Tarantool instance in this format: <host>:<port>. It is passed through to Vshard as part of uri parameter.
name – same as name in Vshard.
master – same as master in Vshard. The role of the instance. DO NOT set master=true for multiple instances in one replica set. This parameter will be changed dynamically during the lifecycle of Autovshard. It can also be changed by administrator at any time. It is safe to set master=false for all instances.
Put this into your tarantool init.lua.
localbox_cfg= {
listen=3301, -- requiredinstance_uuid="aaaaaaaa-aaaa-aaaa-aaaa-000000000001", -- required for storage instances, prefer lowercasereplicaset_uuid="aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa", -- required for storage instances, prefer lowercasereplication_connect_quorum=0, -- recommended, search Tarantool issue tracker for "quorum" and "bootstrap"replication_connect_timeout=5, -- to start faster when some replicas are unavailable-- ! DO NOT set `replication` parameter, Vshard will take care of it-- specify any other_box_cfg options
}
autovshard=require("autovshard").Autovshard.new{
box_cfg=box_cfg, -- Tarantool instance configcluster_name="mycluster", -- the name of your sharding clusterlogin="storage", -- login for Vshardpassword="storage", -- password for Vshardconsul_http_address="http://127.0.0.1:8500", -- assuming Consul agent is running on localhostconsul_token=nil,
consul_kv_prefix="autovshard",
-- consul_session_ttl = 60 -- optional, not recommended to change, default is 15 secondsrouter=true, -- true for Vshard router instancestorage=true, -- true for Vshard storage instanceautomaster=true, -- enables automatic master election and auto-failover
}
autovshard:start() -- autovshard will run in the background-- to stop it call autovshard:stop()-- This might be helpful (Tarantool >= 2.0)-- box.ctl.on_shutdown(function() autovshard:stop(); require("fiber").sleep(2) end)-- If you use package.reload (https://github.com/moonlibs/package-reload)-- package.reload:register(autovshard, autovshard.stop)
Important: If Consul is unreachable the Tarantool instance is set to read-only mode.
Autovshard Tarantool config parameters
box_cfg – table, parameters for box.cfg call
cluster_name – string, the name of your sharding cluster
login – string, login for Vshard
password – string, password for Vshard
consul_http_address – a string with Consul address or a table of multiple Consul addresses.
Examples: "http://127.0.0.1:8500", {"https://consul1.example.com:8501", "https://consul2.example.com:8501"}
If multiple Consul addresses are set and Consul is unreachable at an address, Autovshard will use the
next address from the array for the subsequent requests to Consul.
Note: All addresses must point to the instances of the same Consul cluster in the
same Consul datacenter.
consul_token – optional string, Consul token (if you use ACLs)
consul_kv_prefix – string, a prefix in Consul KV storage. Must be the same on all instances in a Tarantool cluster.
consul_session_ttl – optional number, Consul session TTL. Not recommended to change, default is 15 seconds. Must be
between 10 and 86400.
router – boolean, true for Vshard router instances
storage – boolean, – true for Vshard storage instance
automaster – boolean, enables automatic master election and auto-failover
Luarocks sucks at pinning dependencies, and Vshard does not support (as of 2019-07-01) painless
installation without Tarantool sources. Therefore Vshard is not mentioned in the rockspec.
Internally Autovshard does 2 things (which are almost independent of each other):
Watch the config in Consul and apply it as soon as it changes. Whatever the config is, it is converted to Vshard config and passed to vshard.storage.cfg() and vshard.router.cfg() according to the parameters of the Autovshard Tarantool config. If Consul is unreachable, Autovshard sets the Tarantool instance to read-only mode to avoid having multiple master instances in a replicaset (this feature is called fencing).
Maintain master election with a distributed lock and change the config in Consul when the lock is acquired. This is done only on Vshard storage instances when automaster is enabled. Autovshard only changes master field of the Autovshard Consul config.
You can check out CI e2e tests logs to get familiar with what Autovshard prints to the Tarantool log in different situations.
Notes on Consul
It is recommended to run Consul agent on each server with Tarantool instances and set consul_http_address to the address of the agent on localhost.