--- Log opened Sat Jun 30 00:00:52 2018 20180630 01:44:05-!- janebot [~Gambot@unaffiliated/gambit/bot/gambot] has quit [Remote host closed the connection] 20180630 01:44:23-!- janebot [~Gambot@unaffiliated/gambit/bot/gambot] has joined #wesnoth-umc-dev 20180630 04:55:34-!- hk238 [~kvirc@unaffiliated/hk238] has joined #wesnoth-umc-dev 20180630 04:55:35< hk238> hi 20180630 04:55:54< hk238> does for pairs do cause OoS? 20180630 05:01:53< 21WAANAI7> Yes. It's easily possible that the table iteration order is different for distinct players. 20180630 05:02:22< 21WAANAI7> https://wiki.wesnoth.org/LuaWML#Random_Lua_table_iteration 20180630 07:44:53< hk238> oh 20180630 07:45:18< hk238> btw is it that "wesnoth.random" is somehow synchronized? 20180630 07:58:01< hk238> hmm in anycase I guess with weather function causes oos 20180630 07:58:14< hk238> although it remains to be seen still, but it should cause oos 20180630 08:00:21< 21WAANAI7> IIRC the wiki says if it's synchronized or not 20180630 08:01:40< 21WAANAI7> Yes, wesnoth.random() is synchronized and generates the same numbers for every player (but note that you need to call it the same number of times for all players). 20180630 08:01:59< 21WAANAI7> Meanwhile math.random() is not synchronized. 20180630 08:21:15< hk238> https://pastebin.com/VZvB9sSW 20180630 08:21:32< hk238> this is probably the function that results to weather getting OoS it doesn't happen everytime, I guess it's due to the weighted odds 20180630 08:21:48< hk238> I mean that it's somewhat likely to get the same result despite different order of addition 20180630 08:22:04< 21WAANAI7> No, it's because of the use of pairs(). 20180630 08:22:18< 21WAANAI7> wesnoth.random() returns the same number for all players. 20180630 08:22:23< hk238> yes that's what I mean 20180630 08:22:27< hk238> sorry if that was unclear 20180630 08:22:33< hk238> there's the pairs loop inside this function 20180630 08:23:21< 21WAANAI7> My point is that the problem would occur even if the odds weren't weighted. 20180630 08:23:46< hk238> yes of course 20180630 08:24:01< hk238> it's just that I tested it a couple of times and the weather was the same surprisingly for a while 20180630 08:24:02< hk238> :D 20180630 08:24:30< hk238> it's luck anyway 20180630 08:24:58< 21WAANAI7> I don't recall offhand why exactly the iteration order of pairs() is unspecified. 20180630 08:25:17< 21WAANAI7> It's possible that the order is, for example, OS specific in practice. 20180630 08:25:30< 21WAANAI7> (However, you shouldn't rely on it.) 20180630 08:30:34< hk238> if I had to guess it might a processor thread optimization based on asynchronous processing and also the argument given in the Go lang article you posted yesterday 20180630 08:31:39< hk238> but there's also that there's no reason to assume that there exists an ordering with an operator that's transitive for a particular kind of set of keys 20180630 08:32:13< hk238> if they keys are numbers, then it's obvious that there exists one, because everyone intiutively knows that if a < b and b < c then it must also be that a < c 20180630 08:33:12< hk238> but if you have some other kind of function than "<" for an example a,b,c are people and test function symmetric.. what's the term for that? reflexive? I forgot the term should check on that. 20180630 08:33:37< hk238> well for an example let's say the function is a test for a proposition "a likes b and b likes a back" 20180630 08:34:10< hk238> then you cant order them like a likes b, but b also a.. this is bad example 20180630 08:34:27< hk238> rather let's say it's "a owes b money" 20180630 08:34:55< hk238> it might be true that person "a" owes person "b" money, and person "b" owes person "c" money, but it's not true that a owes c money 20180630 08:35:22< 21WAANAI7> In practice, it could also be something like this, combined with using a hash table to represent the table. 20180630 08:35:22< 21WAANAI7> https://stackoverflow.com/questions/27522626/hash-function-in-python-3-3-returns-different-results-between-sessions 20180630 08:35:33< hk238> so if you process they keys in a random order and use a "which person owes which money" 20180630 08:36:04< hk238> then the order you get from sorting is random because it's based on the order they're evaluated 20180630 08:36:23< hk238> so like in the example from yesterday, in javascript the most obvious operators are not actually transitive, like "<" 20180630 08:36:49< hk238> because they compare all kinds of weird things like empty array [], number 5, string of number of number 5 "5" 20180630 08:36:58< 21WAANAI7> (In Python's case, the order has always been different across 32-bit and 64-bit builds. It may well also be the case for Lua.) 20180630 08:37:15< hk238> and it turns out the operator is not transitive so if you run a sort on a pool of items like that, then the initial order decides how it ends up getting sorted 20180630 08:37:33< hk238> oh maybe that's the case :o 20180630 08:39:09< hk238> actually the term for symmetric was just symmetric and reflexive means true for self like if the operator is "=" then its' true that for every number x "x = x" is true 20180630 08:39:19< hk238> it's also symmetric because if "x = y" then it's true that "y = x" 20180630 08:40:20< hk238> meanwhile ordering basically means that it's not true that it's symmetric and it's transitive, like < for numbers. If x < y then it's not true that y < x, so it's not symmetric. But it's also not reflexive because "x < x" is not true 20180630 08:41:34< hk238> hmm I probably didn't get all the required criterion into this 20180630 08:42:58< hk238> but anyway you can test that if "x < y" is true, then you put x before y. If it's false, then you put y before x. But there's a problem also... Okay so what's the name of the property that if "x < y" is false, then "y < x" is true? It's not true for numbers because they can be the same, meanwhile the inverse is true 20180630 08:43:14< hk238> if "x < y" is true then it's false that "y < x" because x < y implies that they're not the same number 20180630 08:43:57< hk238> so you can create a predicate function that takes two items, compares them, and decides the order based on if the comparisons are true or false 20180630 08:44:23< hk238> but not all comparisons have the capacity to create an exact ordering, it might exists 20180630 08:44:56< hk238> there also number systems where this doesn't work, but I don't know much about that.. but I guess in programming it's mostly that when the comparisons involve non-numeric items it's not at all obvious that the ordering is possible 20180630 08:45:51< hk238> but since strings can be represented by numbers, and you can use the numbers used for that purpose, it's possible to sort strings relying on the property of numbers. But to say that it's somehow the correct order of a key-value mapping is stretching it :D 20180630 08:46:38< 21WAANAI7> When strings are stored in a sorted order, it's essentially always lexicographical order. 20180630 08:47:17< 21WAANAI7> And anyway, this is a moot point. Lua does not guarantee any order for table iteration, which suggests that they are not sorting the keys at all. 20180630 08:47:26< 21WAANAI7> Most likely they use a hash table. 20180630 08:47:50< hk238> yeah :o 20180630 08:48:32< hk238> so if I wanted to fix this function I should sort the table first.. If I do a sorting on a table does it mean that after that it has an order and they keys can be accessed by the index also? 20180630 08:48:39< hk238> I guess that would be in the manual : 20180630 08:48:40< hk238> :o 20180630 08:49:16< 21WAANAI7> No. You can't sort table keys. You can only sort values. 20180630 08:49:42< 21WAANAI7> A "sorted table" would be a table with numeric indices, and the original keys as its values. 20180630 08:51:44< hk238> right that does true key-value pairs represent a mapping from keys to values, and a way to represent an ordering of the keys is to map them into an array so that each index corresponds to a key.. which is exactly what you said I guess :D 20180630 08:52:20< hk238> but in practice what would be the most logical way to fix this OoS issue? To create an ordering by creating a mapping of numeric indices to key values and then use that for the iteration? 20180630 08:53:28< 21WAANAI7> You could change the format of weather_table so that its keys are numbers, and iterate it with ipairs(). 20180630 08:54:13< 21WAANAI7> In the caller, store the possible weather options in another table (each key is a number, each value is a weather string). 20180630 08:54:16< hk238> hm so instead of ["clear"] = { "clear" = 5, 20180630 08:54:22< hk238> I'd do something like 20180630 08:54:32< 21WAANAI7> In short, use two tables to list weather options (one for names, the other for probabilities). 20180630 08:54:58< hk238> ["clear"] = { [1] = { "clear" = 5 }, [2] = { "rain" = 3 } } 20180630 08:54:59< hk238> ? 20180630 08:55:28< 21WAANAI7> what if you created an array with X amount of each key, where X is the weight of the key? 20180630 08:55:43< 21WAANAI7> then by selecting random one you get your weighted selection 20180630 08:55:45< hk238> that would work landiss but it would not be a convenient way of writing it 20180630 08:55:53< 21WAANAI7> how so? 20180630 08:55:56< hk238> but at least it works meanwhile this doesn't work 20180630 08:56:00< 21WAANAI7> This is what I mean: https://gist.github.com/jyrkive/e72f042f8b51b16884f35f30cbe5d93a 20180630 08:56:00< 21WAANAI7> I mean create that bnased on the table you have 20180630 08:56:14< 21WAANAI7> then the order doesn't matter 20180630 08:56:54< hk238> that's definitely an option Jyrkive 20180630 08:59:32< hk238> mulla alkaakin saunavuoro (sauna time) 20180630 08:59:32< hk238> :D 20180630 10:09:38< hk238> ahh I guess I'll try and make some sort of sort function 20180630 10:11:20< hk238> is there a method to swap indexes around or do I have to create that? I guess I should look at the manual again :o 20180630 10:22:06< hk238> btw is there some built-in syntax for type checking / forcing 20180630 10:22:38< hk238> like can you write in parameters "int my_number" and then if it's not an integer an error is raised, or something along those lines? 20180630 10:22:53< Ravana_> http://lua-users.org/wiki/LuaTypeChecking 20180630 10:24:20< hk238> hm 20180630 10:24:53< hk238> I guess that means there's for the most part no type checking syntax, but it's possible to create checks if need be manually? 20180630 10:25:43< hk238> I think it's good at least that the arithmetic operators are not doing any type coercions, which would be and endless source of errors :D 20180630 10:26:21< hk238> but it would be very convenient to have syntax for type checking in C style 20180630 10:26:36< hk238> but of course a lot of things would be convenient in life 20180630 10:26:41< hk238> and they're not always there :D 20180630 10:29:00< hk238> I think not having forced type checking on the other hand is convenient too 20180630 10:30:14< hk238> by the way can you have properties attached to functions? 20180630 10:32:45< hk238> this page is interesting :D 20180630 10:34:45< hk238> I was wondering if you could create typechecking in a similar manner as is done on the page above, but instead by attaching a propery to a function that says what the types are supposed to be 20180630 10:35:04< hk238> and then boxing the functions into functions with optional type checks 20180630 10:36:04< hk238> something like function["expected_types"] = { "integer", "string", "unspecified" }  20180630 10:36:37< hk238> and thne you'd do the boxing like box_function_with_typecheck(function), which returns a typechecking function 20180630 10:37:26< hk238> And then the function calls would be threaded through the typechecking function.. which is basically the same thing as described on the page 20180630 10:37:36< hk238> but with the difference that it's using a different style of notation for the types 20180630 10:38:32< hk238> meanwhile I should finally try and fix this weather thing 20180630 10:38:32< hk238> :D 20180630 10:56:42< hk238> https://pastebin.com/eZtumNkG 20180630 10:56:54< hk238> here's an ordering function but it's quite terrible in many ways :D 20180630 10:58:26< 21WAANAI7> How can I filter the attacker's used attack's range in a name=attacker hits event? I'm trying to add a filter that only passes if the attacker used a melee range attack 20180630 10:59:59< hk238> I think it might be range=melee or something like that bjut I dont remember 20180630 11:00:10< hk238> probably I remember it wrong:D 20180630 11:00:14< hk238> Im going to make some coffee 20180630 11:01:04< 21WAANAI7> Yeah I've tried something like [filter] range=melee [/filter] But it passes even if they used a ranged attack when hitting 20180630 11:02:02< 21WAANAI7> Kind of like it's checking if the unit has -any- melee range attacks, not just the attacked that was actually used 20180630 11:04:53< 21WAANAI7> Nope, it just passes even if the attacker has no melee range attacks (checked with Dark Adept). 20180630 11:05:27< 21WAANAI7> So, yeah, I dunno how to filter the attacker's used attack's range to only have the filter pass if the used attack was a melee ranged one 😐 20180630 11:07:38< 21WAANAI7> https://wiki.wesnoth.org/FilterWML#Filtering_Weapons mentions filtering for range, but I dunno how to apply it to the actual attack that was used to hit (in a "attacker hits" event) 20180630 11:07:46< hk238> I think it's that you have to use [filter_attack] instead of [filter] 20180630 11:07:49< hk238> https://wiki.wesnoth.org/EventWML#.5Bfilter_attack.5D 20180630 11:08:06< hk238> ". This is usable in the events attack, attacker hits, attacker misses, defender hits, defender misses, attack end, last breath, and die " 20180630 11:08:14< 21WAANAI7> Aahh, of course! 20180630 11:08:27< 21WAANAI7> Derp. I saw that one earlier, but had forgotten about it. 20180630 11:08:32< 21WAANAI7> Thanks, buddy 😃 20180630 11:08:39< hk238> np 20180630 11:08:42< hk238> : D 20180630 11:08:42< 21WAANAI7> Will try it out 20180630 11:10:19< 21WAANAI7> Even more embarrasing when I've already used [filter_attack] rather recently in other filters 😓 20180630 11:11:17< 21WAANAI7> hk238: you don't need to implement your own sorting, you can just use table.sort(). 20180630 11:11:43< hk238> but I think you said earlier it's only possible to sort values not keys? :o 20180630 11:11:56< 21WAANAI7> (Although doing that requires that you don't call the parameter table. Right now you're making Lua's built-in table table inaccessible.) 20180630 11:12:25< hk238> what does that mean? :D 20180630 11:12:25< 21WAANAI7> Correct. So you need to create a table where the strings are values, then sort that table. 20180630 11:13:11< hk238> right so basically that means that I'd need to do something along the lines of what I'm doing, right? Since it's creating a sorted array of index, value pairs were the values are the keys? 20180630 11:13:29< hk238> although that function probably has lots of bugs :D 20180630 11:13:46< hk238> hideous multiloop nesting taking place but I don't know how to not do it like that currently 20180630 11:14:13< 21WAANAI7> https://gist.github.com/jyrkive/fcdbda02cc4b14e66f1cfc641eb78be7 20180630 11:15:18< hk238> oh you mean I shouldn't use "table" as a parameter name? It's an actual keyword? 20180630 11:15:27< hk238> oh that's what you said 20180630 11:15:30< hk238> but I didn't understand 20180630 11:15:37< hk238> which is why I asked what does it mean :D 20180630 11:15:43< hk238> okay so I'll rename them 20180630 11:15:47< 21WAANAI7> Works as it should now, with the correct filter 😉 👍 20180630 11:15:50< 21WAANAI7> It's not a keyword. You are allowed to shadow the table table. 20180630 11:16:04< 21WAANAI7> You just can't access any of its functions if you do that. 20180630 11:17:12< 21WAANAI7> https://gist.github.com/jyrkive/db6c9b80884da6a3f667af4abdf721b7 20180630 11:17:17< 21WAANAI7> There. That's all you need to do. 20180630 11:18:54< hk238> what kind of test does "table.sort" use for ordering though? 20180630 11:19:05< 21WAANAI7> Lexicographical order. 20180630 11:19:38< hk238> okay :o 20180630 11:20:10< hk238> but making this function was useful still 20180630 11:20:46< hk238> although I think this symmetry test is a problem 20180630 11:21:20< hk238> you can create a function that compares the words by some arbitrary reason :D 20180630 11:22:06< 21WAANAI7> You can do the same with table.sort(). It accepts an optional comparison function as the second parameter. 20180630 11:22:06< hk238> speaking of which is there a test function that the table.sort is using? like can I use that as the predicate function? 20180630 11:22:14< hk238> oh 20180630 11:22:30< 21WAANAI7> You can simply use str1 < str2. 20180630 11:22:47< hk238> okay I guess that's nice 20180630 11:23:25< hk238> so if I wanted to make < itno a function I would just call it string_compare(str1,str2) return str1 < str2 end? 20180630 11:23:46< hk238> I wonder if I should go out to the flea market it's still open :o 20180630 11:24:21< 21WAANAI7> Indeed, such a string compare function would work. 20180630 11:24:44< 21WAANAI7> (Although such a function doesn't make much sense unless you need to pass it as a parameter to a higer-order function.) 20180630 11:24:48< hk238> kind of highlighting that the operator is in a sense syntactic sugar for such a function 20180630 11:24:50< 21WAANAI7> *higher 20180630 11:24:56< hk238> :D 20180630 11:25:05< hk238> yes that's exactly the point 20180630 11:25:59< hk238> although in this case there's no problem because keys must be unique 20180630 11:26:14< hk238> but if they were the values that were being sorted, then multiple keys could point to the same value 20180630 11:26:29< hk238> like if you consider the association "clear" and 3 with the association of "clear" and 5 20180630 11:26:40< hk238> althoug they're equal by string comparison they're not equal in their association 20180630 11:26:56< 21WAANAI7> You can't do that with a Lua table. 20180630 11:27:11< hk238> yes that's the idea 20180630 11:27:46< hk238> I mean you can of course have { ["3"] = "clear", ["5"] = "clear" } 20180630 11:28:10< hk238> but if you sort the pairs by the value 20180630 11:28:47< hk238> there's a problem since "clear"_1 < "clear"_2 is false and "clear"_2 < "clear"_1 is false too 20180630 11:29:17< hk238> It's not really important it's just a technical detail along the lines of the earlier conversations 20180630 11:29:25< hk238> about the imperfection of different types of sorting 20180630 11:29:40< hk238> when there are identical items in the list then there doesn't exist one true order for the items 20180630 11:29:42< Ravana_> try design your data to not need sorting 20180630 11:29:48< hk238> instead there exists multiple orderings 20180630 11:30:02< hk238> just if you have some assortment of numbers like 1,3,3,5 20180630 11:30:46< hk238> if you tag the 3s and have them have distinct identiy, for an example via this kind of association in a key-value pair 20180630 11:31:39< hk238> then there not being one true order can cause issues, like for an example due to the iterators undefined access order, it might result to unusual probabilities for an example 20180630 11:31:59< hk238> like you could end up in a situation where you are suppsoed to have 50% chance to get either of 3s and their associated value 20180630 11:32:11< hk238> but because the string compare sorting function can't sort two 3s 20180630 11:32:24< hk238> you might end up in a situation where the probability isn't 50% 20180630 11:33:46< hk238> whether or not that actually happens with lua is unknown to me 20180630 11:34:22< 21WAANAI7> It can't happen with the table.sort() default comparer. 20180630 11:34:31< hk238> but I wouldn't surprised if you construct a situation in which the underlying lack of one true sorting order could result to the iterator's internal mechanics influencing the different orders 20180630 11:34:34< 21WAANAI7> It can only compare strings and numbers. 20180630 11:34:49< hk238> no that's not the reason that defines whether or not it can happen 20180630 11:35:20< hk238> it's a question of whether or not the sorting actually includes an additional step to randomize the order of equivalent items 20180630 11:35:30< 21WAANAI7> If you instead have a table of key-value pairs, you need to write your own comparer, and it's your responsibility to ensure that it fully defines an order for all elements if you need it. 20180630 11:36:54< 21WAANAI7> Lua's sorting doesn't intentionally randomize the order of equal elements, but the sorting algorithm may swap them anyway because it's a so-called unstable sorting algorithm. 20180630 11:37:10< hk238> right 20180630 11:37:30< 21WAANAI7> (I recall that at one point in development of Angry Birds Stella I needed stable sorting in Lua. I wrote my own sorting function for that.) 20180630 11:37:34< hk238> so I think it's safe to say that the unstable sorting algorithm might not have uniform probability distributions for all possible ways of sorting stuff 20180630 11:37:55< hk238> oh cool 20180630 11:38:26< hk238> so it's true too 20180630 11:38:26< 21WAANAI7> Only if you find yourself sorting a table with multiple equal elements. 20180630 11:38:45< hk238> yes that's kind of topic here :D 20180630 11:39:02< hk238> sorry :o 20180630 11:39:17< 21WAANAI7> In the ordered_map_of_keys() implementation I posted, all elements are guaranteed to be unique and "not having uniform probability distributions" is impossible. 20180630 11:41:42< hk238> that's not true 20180630 11:41:58< 21WAANAI7> https://gist.github.com/jyrkive/db6c9b80884da6a3f667af4abdf721b7 20180630 11:42:00< hk238> I mean it is true, but only because it's sorting keys which are unique 20180630 11:42:15< hk238> but it's not that the algorithm itself provides means for unique distributions 20180630 11:42:38< hk238> you can make table.sort into a stable sort pretty easily, by writing a boxing function around it that randomizes the order of equivalent items 20180630 11:42:45< 21WAANAI7> I said "the ordered_map_of_keys() implementation I posted". 20180630 11:43:11< 21WAANAI7> It doesn't matter that it's not the underlying sorting implementation that provides the guarantee. 20180630 11:44:24< 21WAANAI7> Building stable sorting out of unstable sorting doesn't make much sense. I implemented the insertion sort algorithm instead. It was, what, ten lines? 20180630 11:44:50< 21WAANAI7> Focefully restoring order after calling table.sort() would have taken more lines than that. 20180630 11:44:52< hk238> it might make sense if you're dealing with very large tables 20180630 11:45:02< hk238> unstable sorting is probably a result of having an efficient algorithm 20180630 11:45:32< hk238> so it might make sense if you have 10 million things to sort 20180630 11:47:11< 21WAANAI7> In that case using a fast stable sorting algorithm such as mergesort would still win using unstable sort and restoring order afterwards. 20180630 11:47:43< hk238> I'm not convinced that's true, in fact I think it's highly likely that it's false 20180630 11:48:17< hk238> but it probably wins when the number of things to sort is very low 20180630 11:50:10< hk238> it's probably also a question of the proportional number of equivalent items 20180630 11:50:44< hk238> but I could be wrong, you could be right, it's just my current opinion which is not reliable 20180630 11:54:45< 21WAANAI7> https://www.geeksforgeeks.org/stability-in-sorting-algorithms/ 20180630 11:54:55< 21WAANAI7> "Any given sorting algo which is not stable can be modified to be stable. There can be sorting algo specific ways to make it stable, but in general, any comparison based sorting algorithm which is not stable by nature can be modified to be stable by changing the key comparison operation so that the comparison of two keys considers position as a factor for objects with equal keys." 20180630 11:55:55< 21WAANAI7> So, one way to achieve stable sort with table.sort() would be by passing in a custom comparison function that uses the original index of the element as the secondary comparison criterion. 20180630 11:56:20< 21WAANAI7> (Note that you'd need to store the original indices first. You can't scan the table while it's being sorted.) 20180630 12:00:34< hk238> :o 20180630 12:13:32< hk238> I decided use your ordered map function afterall 20180630 14:34:03-!- janebot [~Gambot@unaffiliated/gambit/bot/gambot] has quit [Remote host closed the connection] 20180630 14:34:09-!- janebot [~Gambot@unaffiliated/gambit/bot/gambot] has joined #wesnoth-umc-dev 20180630 16:10:30-!- janebot [~Gambot@unaffiliated/gambit/bot/gambot] has quit [Remote host closed the connection] 20180630 16:10:36-!- janebot [~Gambot@unaffiliated/gambit/bot/gambot] has joined #wesnoth-umc-dev 20180630 18:22:55-!- janebot [~Gambot@unaffiliated/gambit/bot/gambot] has quit [Remote host closed the connection] 20180630 18:23:01-!- janebot [~Gambot@unaffiliated/gambit/bot/gambot] has joined #wesnoth-umc-dev 20180630 18:46:07-!- 21WAANAI7 [~discordbo@baldras.wesnoth.org] has quit [Remote host closed the connection] 20180630 18:46:27-!- discordbot1 [~discordbo@baldras.wesnoth.org] has joined #wesnoth-umc-dev 20180630 19:32:17-!- janebot [~Gambot@unaffiliated/gambit/bot/gambot] has quit [Remote host closed the connection] 20180630 19:32:23-!- janebot [~Gambot@unaffiliated/gambit/bot/gambot] has joined #wesnoth-umc-dev 20180630 19:54:13-!- hk238 [~kvirc@unaffiliated/hk238] has quit [Quit: KVIrc 5.0.0 Aria http://www.kvirc.net/] --- Log closed Sun Jul 01 00:00:54 2018