Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 443 444 [445] 446 447 ... 796

Author Topic: if self.isCoder(): post() #Programming Thread  (Read 886712 times)

alway

  • Bay Watcher
  • 🏳️‍⚧️
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6660 on: November 19, 2014, 09:52:03 pm »

Also, Microsoft open-sourced1 the .NET core recently, so that's probably going to get some extra support.

1most far-fetched phrase in the news of the month goes to
Also, they released a free version of Visual Studio. Aside from licensing limitations, it's just VS2013 Professional edition for free.
http://www.visualstudio.com/en-us/visual-studio-community-vs.aspx

Quote
"For all other usage scenarios: In non-enterprise organizations, up to 5 users can use Visual Studio Community. In enterprise organizations (meaning those with >250 PCs or > $1MM in annual revenue), no use is permitted beyond the open source, academic research, and classroom learning environment scenarios described above."
That's literally the only limitation. Free as in buy Microsoft a beer for being cool.
« Last Edit: November 19, 2014, 09:57:15 pm by alway »
Logged

Thief^

  • Bay Watcher
  • Official crazy person
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6661 on: November 20, 2014, 03:29:14 am »



That c++ example won't work backwards, though, you can't use it to determine what values make that rule true.

For example if you write a pathfinder, you can use that to get a path from A to B, get all paths from A to B, get all paths from A to any node, get all paths from any node to B, get all possible paths between all nodes, or get the start and end node of a specified path (which probably isn't that useful, but it will still do it), Without writing a single line of extra code.

If you create some rules to validate a player's move in a game, that same rule can be used to get potential moves for an AI, for example.

I am pretty sure that example won't work on runtime lists too, making the use cases for it very different.
You're right, it models the functional approach without prolog's first-order-logic solver.

It won't work as written for runtime lists, because templates are a compile-time construct. You can write a functional version for runtime, but it looks a little different because C++ is quite strict and won't do dynamic dispatch to different functions based on runtime data:
Code: [Select]
bool contains(int i_find, std::vector<int> list)
{
  return list.empty() ? false : (*list.begin() == i_find ? true : contains(i_find, {list.begin()+1, list.end()}));
}

Note that this version is exactly as inefficient as any naïve implementation of functional lists, in that it unnecessarily copies n-1 elements to a new list every iteration. Fixing this requires coding a relatively trivial "range" class, which a version of (along with adapting the entire std::algorithms library to support it) is currently being standardised.
« Last Edit: November 20, 2014, 03:31:50 am by Thief^ »
Logged
Dwarven blood types are not A, B, AB, O but Ale, Wine, Beer, Rum, Whisky and so forth.
It's not an embark so much as seven dwarves having a simultaneous strange mood and going off to build an artifact fortress that menaces with spikes of awesome and hanging rings of death.

alexandertnt

  • Bay Watcher
  • (map 'list (lambda (post) (+ post awesome)) posts)
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6662 on: November 20, 2014, 06:36:20 am »

What is this {list.begin(), list.end()} thing? (the curly brackets making a vector). It looks like some sort of inline list thing, but from googling I don't think thats quite it.
Logged
This is when I imagine the hilarity which may happen if certain things are glichy. Such as targeting your own body parts to eat.

You eat your own head
YOU HAVE BEEN STRUCK DOWN!

Thief^

  • Bay Watcher
  • Official crazy person
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6663 on: November 20, 2014, 06:40:01 am »

It's from C++11's uniform initialization syntax, it invokes vector's constructor with those args. Saves a bit of typing :)

Here's a compiled demo of it working:
http://ideone.com/Z1DHOH
« Last Edit: November 20, 2014, 06:49:37 am by Thief^ »
Logged
Dwarven blood types are not A, B, AB, O but Ale, Wine, Beer, Rum, Whisky and so forth.
It's not an embark so much as seven dwarves having a simultaneous strange mood and going off to build an artifact fortress that menaces with spikes of awesome and hanging rings of death.

Antsan

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6664 on: November 20, 2014, 08:59:20 am »

Code: [Select]
contains([AHead|ARest], AHead).
contains([AHead|ARest], B) :- contains(ARest, B).

This is the standard functional approach to doing anything on a list, and can be exceedingly slow if either the interpreter doesn't support list slices or you do something that means it can't use slicing, as you potentially create a new N-1 sized list for every iteration, aka O(N!) complexity O.o
All functional languages and all languages... uhm... supporting functional programming I know use linked lists, where copying to get the rest of a list is completely superfluous.
I don't know where you get the idea that copying is in any way necessary.

Second, Prolog is not a functional programming language and although this special example actually does look like functional code, Prolog looks significantly different from functional languages in other cases. For a real functional language, take a look at Haskell, where the above code cannot be written, because its pattern matching doesn't allow for repeated variable names to test for equality (which is probably because Haskell has no general notion of equality).

Quote
It's from C++11's uniform initialization syntax, it invokes vector's constructor with those args.
Again, if you see syntax like
[A|B]
then you can be almost sure that lists are not modeled as vectors but as tuples of a value and a (possibly empty) list.
I am pretty sure that Prolog uses linked lists, just as Haskell, any other functional language and all Lisps do.

The whole "range" class is a bit strange. In Common Lisp it is done by making a displaced array, which is basically an array sharing structure with another array.
Look here: http://www.lispworks.com/documentation/HyperSpec/Body/f_mk_ar.htm
An example:
Code: [Select]
(defparameter *array* (make-array dim))
(defparameter *array-tail* (make-array (1- dim)
                                            :displaced-to *array*
                                            :displaced-index-offset 1))
Logged
Taste my Paci-Fist

Thief^

  • Bay Watcher
  • Official crazy person
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6665 on: November 20, 2014, 11:01:18 am »

You could change my C++ contains() to have a linked-list arg instead, it will still clone the rest of the list each iteration. Linked lists aren't a magic bullet, and neither is the solution to the cloning problem unusable for vectors :). Linked lists also have known performance issues on modern cpus (http://youtu.be/YQs6IC-vgmo). In normal C++ I could avoid it by using list-mutating functions (i.e. pop_front() and then move() to move the result into the recursion), but that's not the goal here, the goal is to model a pure functional approach. Strictly speaking all the parameters should be const (aka immutable), which would prevent mutating operations.

The standard C++ algorithms currently take pairs of iterators instead, which would make a functional contains look like this:
Code: [Select]
template<typename t, typename it>
bool contains(const t& i_find, it begin, it end)
{
  return begin == end ? false : (*begin == i_find ? true : contains(i_find, std::next(begin), end));
}
which is much uglier to call than the last version (although I have generalized it for use with any type):
Code: [Select]
auto list = {1,2,3,4}
contains(x, list.begin(), list.end());

With ranges you get:
Code: [Select]
template<typename t, typename range>
bool contains(const t& i_find, range&& list)
{
  return list.begin() == list.end() ? false : (*list.begin() == i_find ? true : contains(i_find, std::make_range(std::next(list.begin()), list.end())));
}
http://ideone.com/gyso7m
which is almost identical to what I wrote originally (although again, generalized for any type/container), and can be called directly with a list or any other container type, or even a range (as is done in the recursion).
It doesn't work on a bare initializer list without an extra overload because an initializer list is not a deducible type in C++.


If you really want it for tuples (the types of the elements in the tuple are fixed at compile-time in C++) you can do:
Code: [Select]
template<typename t_find>
bool contains(const t_find& i_find)
{
    return false;
}

template<typename t_find, typename... t_rest>
bool contains(const t_find& i_find, t_find&& i_head, t_rest&&... i_rest)
{
    return i_find == i_head ? true : contains(i_find, std::forward<t_rest>(i_rest)...)
}

template<typename t_find, typename t_head, typename... t_rest>
bool contains(const t_find& i_find, t_head&& i_head, t_rest&&... i_rest)
{
    return contains(i_find, std::forward<t_rest>(i_rest)...)
}
http://ideone.com/kaD2lU
As with the totally compile-time template version I put up first, this version employs functional-language-like tricks like repeating the same name twice in one overload and using two different names in another to automatically call one version if the types are equal, and popping an element off a list by having an explicit variable for the head and an unspecific list for the "rest" to slice a list.

(this version maps the "tuple" from functional languages to c++'s variadic parameter packs, if you want it for an std::tuple, you either need a way to slice a tuple or you just "apply" the tuple to this version to unpack it into the function arguments)
(this version will only compare objects of matching type and assumes everything else doesn't match, if you want to allow comparison between different types you probably need to use enable_if on whether such a comparison operator exists to avoid a compile-time error, but it's still very much doable. Most purely functional languages are runtime-typed, so would either automatically return false from such a comparison or throw a runtime error (needing a similar workaround))

If you want runtime *types* as well as values, then you'd simply need to use a "variant" type with one of the above versions (probably the range one).

Prolog is indeed something that C++ can't directly model, thanks to its built-in first-order-logic solver, but I'll be damned if it's not possible to do somehow, I'm just not planning to build a logic solver myself to do it :)

EDIT: As a little addendum, I saw something showing a C++ compiler that parsed the C++ source code into a lisp expression tree, essentially turning C++ into lisp and compiling that. With the compiler written in C++, that's some nice circles if you think about it too hard.
« Last Edit: November 20, 2014, 11:12:04 am by Thief^ »
Logged
Dwarven blood types are not A, B, AB, O but Ale, Wine, Beer, Rum, Whisky and so forth.
It's not an embark so much as seven dwarves having a simultaneous strange mood and going off to build an artifact fortress that menaces with spikes of awesome and hanging rings of death.

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6666 on: November 20, 2014, 04:11:16 pm »

With the compiler written in C++, that's some nice circles

*parentheses

Gentlefish

  • Bay Watcher
  • [PREFSTRING: balloon-like qualities]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6667 on: November 21, 2014, 01:42:17 am »

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #6668 on: November 21, 2014, 01:49:32 am »

That just means you explained it in a way that was too complicated and you scared her off :v
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

Orange Wizard

  • Bay Watcher
  • mou ii yo
    • View Profile
    • S M U G
Re: if self.isCoder(): post() #Programming Thread
« Reply #6669 on: November 21, 2014, 01:54:50 am »

Programming is one of those things that some people get and some people don't.
Logged
Please don't shitpost, it lowers the quality of discourse
Hard science is like a sword, and soft science is like fear. You can use both to equally powerful results, but even if your opponent disbelieve your stabs, they will still die.

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #6670 on: November 21, 2014, 01:58:02 am »

From her response, it seems like you threw too many hard words at her.

Quote
Specifically, based on the capsule shell appearance it is the generic Nitrofurantoin. I used to be in the QC unit at the pharma company manufacturing that specific generic. The product was actually on my Team in the QC Lab. I've done a TON of QC HPLC Analysis on those. I knew what they were as soon as I saw the thumbnail.
Those analytical HPLC methods were a huge pain in the ass. The diluent and mobile phase they used were heavy on Dimethylformamide which is great at causing any previous buffer salts present in the lines of an instrument to crash out of solution if you didn't flush the instrument REALLY well. Check valves would freeze, and you'd have to take the instrument out of service.
Still want to learn how I make medicine?

^ like this! Unless you know chemistry well, in which case it doesn't count.
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

Orange Wizard

  • Bay Watcher
  • mou ii yo
    • View Profile
    • S M U G
Re: if self.isCoder(): post() #Programming Thread
« Reply #6671 on: November 21, 2014, 02:01:36 am »

The issue with that argument is that if encountering something that they don't understand is enough to scare them off, then they probably didn't care much about it to begin with. That, or they don't understand what "learning" means.
Logged
Please don't shitpost, it lowers the quality of discourse
Hard science is like a sword, and soft science is like fear. You can use both to equally powerful results, but even if your opponent disbelieve your stabs, they will still die.

Gentlefish

  • Bay Watcher
  • [PREFSTRING: balloon-like qualities]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6672 on: November 21, 2014, 02:05:55 am »

Heh, she understands function and variables and classes. She's just not terribly into programming. She's in art school, after all. She's tried her hand at python, but not much else, and I don't blame her. I mean, I don't into all of her art terminology.

Besides Sky, it's not like I threw a bunch of TCP/IP, DHCP, DNS, ARM, and other acronyms at her, like exist in your excerpt :P

Moghjubar

  • Bay Watcher
  • Science gets you to space.
    • View Profile
    • Demon Legend
Re: if self.isCoder(): post() #Programming Thread
« Reply #6673 on: November 21, 2014, 04:49:54 am »

For those interested, http://www.twitch.tv/handmade_hero  is doing a game programming stream of a start-to-finish game made 'the hard way' (1hr a day, with Q&A afterwards).   Hes more or less doing it the old fashioned way, with a windows target (since of course you didn't program for linux for games, though theres people translating the lessons to Linux, or close enough anyway, using SDL).   I've found it interesting... and sometimes funny at times drinking the tears of twitch chat over the windows api stuff. 

Language: C, maybe some C++ stuff later

"What game engine / libraries are you using?

None! The goal of this project is to show how an entire game is made, not just how to make the part that sits on top of a licensed engine or middleware libraries. Absolutely everything (except the operating system itself) is coded from scratch."

"Is this a DirectX or OpenGL game?

Neither! Because the goal of this project is to teach absolutely all the code necessary for a game to work, even the low-level rendering code will be written from scratch on the stream. Later, for performance, we may make accelerated versions that use 3D hardware, but we will only do this after we've hand-implemented a complete CPU-only renderer first.

"What if I don't have a Windows machine?

Windows accounts for over 90% of all PC game sales, so unfortunately, you pretty much have to learn to code on Windows if you want to ship games to the majority of players. But the good news is, it's not that hard to make a game that runs on multiple platforms, and we'll be doing that as part of the project. So while the first part of the coding will take place on Windows, we'll eventually show how to extend the codebase to run on Mac and Linux."
Logged
Steam ID
Making things in Unity
Current Project: Demon Legend
Also working on THIS! Farworld Pioneers
Mastodon

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #6674 on: November 21, 2014, 04:50:48 am »

That sounds overintimidating... o.O
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward
Pages: 1 ... 443 444 [445] 446 447 ... 796