Skip to content

Instantly share code, notes, and snippets.

View larswaechter's full-sized avatar
👨‍💻
Focusing

Lars Wächter larswaechter

👨‍💻
Focusing
View GitHub Profile
@larswaechter
larswaechter / Board.kt
Created November 29, 2021 19:12
Bitboard for Tic-Tac-Toe in Kotlin
/**
* TicTacToe bitboard
*/
class Board(
val map: LongArray = longArrayOf(
0b000_000_000, // X = player 1
0b000_000_000 // O = player -1
)
) {
companion object {
@larswaechter
larswaechter / park.py
Last active February 22, 2021 17:24
A decent introduction to Gradient Descent in Python
# Medium Article: https://larswaechter.medium.com/a-decent-introduction-to-gradient-descent-in-python-846be2e41592
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
# The model's output (prediction)
def predict(X, w, b):
return X * w + b
@larswaechter
larswaechter / Pointers.c
Last active December 30, 2020 23:28
Array pointer arithmetic in C
int main(int argc, char *argv[])
{
int *arr;
arr = malloc(5);
arr[0] = 1;
arr[1] = 10;
arr[2] = 20;
arr[3] = 30;
arr[4] = 40;
@larswaechter
larswaechter / Node.java
Last active December 17, 2020 17:33
Recursive Node class
public class Node {
int value;
Node next;
Node(int value) {
this.value = value;
}
public int get(int index) {
assert index >= 0 && index < this.length();
@larswaechter
larswaechter / Zobrist.kt
Last active August 2, 2020 14:03
Zobrist Hash in Kotlin by the example of tic-tac-toe
import kotlin.math.pow
import kotlin.random.Random
// Article: https://medium.com/@larswaechter/zobrist-hashing-305c6c3c54d0
/*
* Build the Zobrist table with random numbers.
* For 9 cells and 2 players we need 18 random numbers.
*/
fun buildZobristTable(): Array<Array<Long>> {
@larswaechter
larswaechter / Minimax.kt
Last active August 6, 2020 15:43
Generic Interface for Minimax-Algorithm in Kotlin
/**
* Interface for implementing Minimax algorithm in two-player zero-sum games
* <T> => Move data type
*/
interface Minimax<T> {
// 1 or -1
var currentPlayer: Int
/**
* Evaluate game state for current player.
@larswaechter
larswaechter / Stack.java
Last active December 16, 2021 16:40
Generic Stack Implementation in Java
class Stack<T> implements Stackable<T> {
private Stack<T> previous;
private T value;
Stack() {
}
Stack(T value) {
this.value = value;
}