Skip to content

Instantly share code, notes, and snippets.

View utilForever's full-sized avatar

Chris Ohk utilForever

View GitHub Profile
@utilForever
utilForever / TriangleMesh.cpp
Created August 19, 2019 07:20
Create PxShape using PxTriangleMesh
physx::PxVec3* pPxVerts = new physx::PxVec3[list.vertexCount];
for (int i = 0; i < list.vertexCount; i++)
{
ConvertPosToPhysX(list.pVerts[i], pPxVerts[i]);
}
physx::PxU32* pPxIndices = new physx::PxU32[list.triangleCount * 3];
for (int i = 0; i < list.triangleCount * 3; ++i)
@utilForever
utilForever / localtime.hpp
Created June 16, 2019 07:39
Comparison between localtime_r and localtime_s
#include <ctime>
#include <iostream>
int is_morning_good() {
const time_t now_seconds = time(NULL);
struct tm now;
localtime_r(&now_seconds, &now);
return (now.tm_hour < 12);
}
@utilForever
utilForever / RandomPolicyTest.cpp
Created May 9, 2019 15:17
RosettaStone - Random policy test
TEST(RandomPolicy, Mulligan)
{
for (int i = 0; i < 100; ++i)
{
GameConfig config;
config.player1Class = CardClass::ROGUE;
config.player2Class = CardClass::PALADIN;
config.startPlayer = PlayerType::RANDOM;
config.doShuffle = false;
config.doFillDecks = false;
@utilForever
utilForever / func_timeout.cpp
Last active April 13, 2019 16:51
Timeout function example
#include <chrono>
#include <condition_variable>
#include <iostream>
#include <mutex>
#include <thread>
using namespace std::chrono_literals;
int Func()
{
// This file is a "Hello, world!" in C++ language by GCC for wandbox.
#include <iostream>
#include <regex>
int main()
{
std::regex attackRegex("\\+([[:digit:]]+) Attack");
std::string text = "Raid Leader is granting this minion +1 Attack";
std::smatch values;
@utilForever
utilForever / GraphTest.cpp
Created February 12, 2019 11:11
CubbyDNN graph sample code
using Tensor = Tensor<float>;
Graph g;
auto& input = g.Input(TensorShape(64, 32));
auto& oneHot = g.Reshape(input, TensorShape(1, 2048));
auto& output = g.DropOut(oneHot, 10);
auto& answer = g.Max(result);
for (int i = 0; i < trainNum; ++i)
{
@utilForever
utilForever / Rand.cpp
Created September 19, 2018 16:05
Simple Rand class to roll dice.
#include <random>
#include <iostream>
class Rand
{
public:
Rand()
{
m_generator.seed(m_device());
@utilForever
utilForever / overload.cpp
Last active September 28, 2018 02:15
C++17 overload pattern with std::variant and std::visit (https://www.bfilipek.com/2018/09/visit-variants.html)
#include <iostream>
#include <variant>
struct Fluid { };
struct LightItem { };
struct HeavyItem { };
struct FragileItem { };
struct GlassBox { };
struct CardboardBox { };
@utilForever
utilForever / ParseValueRangeFromString.cpp
Last active May 18, 2018 23:50
Parse value range from std::string (For example, parse 10 or 10-19 only)
inline std::tuple<size_t, size_t> ParseValueRangeFromString(std::string str,
bool& isValid)
{
std::regex reValueRange("([[:digit:]]+)(-[[:digit:]]+)?");
std::smatch values;
size_t minValue = 0, maxValue = std::numeric_limits<size_t>::max();
if (!str.empty())
{
if (std::regex_match(str, values, reValueRange))
@utilForever
utilForever / Enums.h
Created May 11, 2018 16:01
VS compatible better-enums
/*************************************************************************
> File Name: Enums.h
> Project Name: Hearthstone++
> Author: Chan-Ho Chris Ohk
> Purpose: Enumerations for card data.
> Created Time: 2017/08/11
> Copyright (c) 2017, Chan-Ho Chris Ohk
*************************************************************************/
#ifndef HEARTHSTONEPP_ENUMS_H
#define HEARTHSTONEPP_ENUMS_H