1 ! Copyright (C) 2024 Alexander Ilin.
2 ! See https://factorcode.org/license.txt for BSD license.
3 USING: accessors command-line formatting io kernel make math
4 math.parser namespaces sequences ;
13 : Item.ToString ( item -- str )
14 [ Name>> ] [ SellIn>> ] [ Quality>> ] tri "%s %d %d" sprintf ;
16 :: GildedRose.UpdateQuality ( this -- )
17 this Items>> length [| i |
18 i this Items>> nth Name>> "Aged Brie" = not
19 i this Items>> nth Name>> "Backstage passes to a TAFKAL80ETC concert" = not
21 i this Items>> nth Quality>> 0 > [
22 i this Items>> nth Name>> "Sulfuras, Hand of Ragnaros" = not [
23 i this Items>> nth Quality>> 1 -
24 i this Items>> nth Quality<<
28 i this Items>> nth Quality>> 50 < [
29 i this Items>> nth Quality>> 1 +
30 i this Items>> nth Quality<<
31 i this Items>> nth Name>> "Backstage passes to a TAFKAL80ETC concert" = [
32 i this Items>> nth SellIn>> 11 < [
33 i this Items>> nth Quality>> 50 < [
34 i this Items>> nth Quality>> 1 +
35 i this Items>> nth Quality<<
38 i this Items>> nth SellIn>> 6 < [
39 i this Items>> nth Quality>> 50 < [
40 i this Items>> nth Quality>> 1 +
41 i this Items>> nth Quality<<
48 i this Items>> nth Name>> "Sulfuras, Hand of Ragnaros" = not [
49 i this Items>> nth SellIn>> 1 -
50 i this Items>> nth SellIn<<
53 i this Items>> nth SellIn>> 0 < [
54 i this Items>> nth Name>> "Aged Brie" = not [
55 i this Items>> nth Name>> "Backstage passes to a TAFKAL80ETC concert" = [
56 i this Items>> nth Quality>> 0 > [
57 i this Items>> nth Name>> "Sulfuras, Hand of Ragnaros" = not [
58 i this Items>> nth Quality>> 1 -
59 i this Items>> nth Quality<<
63 i this Items>> nth Quality>> i this Items>> nth Quality>> -
64 i this Items>> nth Quality<<
67 i this Items>> nth Quality>> 50 < [
68 i this Items>> nth Quality>> 1 +
69 i this Items>> nth Quality<<
78 "+5 Dexterity Vest" 10 20 Item boa ,
79 "Aged Brie" 2 0 Item boa ,
80 "Elixir of the Mongoose" 5 7 Item boa ,
81 "Sulfuras, Hand of Ragnaros" 0 80 Item boa ,
82 "Sulfuras, Hand of Ragnaros" -1 80 Item boa ,
83 "Backstage passes to a TAFKAL80ETC concert" 15 20 Item boa ,
84 "Backstage passes to a TAFKAL80ETC concert" 10 49 Item boa ,
85 "Backstage passes to a TAFKAL80ETC concert" 5 49 Item boa ,
86 ! This conjured item does not work properly yet.
87 "Conjured Mana Cake" 3 6 Item boa ,
88 ] { } make GildedRose boa
90 command-line get [ 2 ] [ first dec> ] if-empty [
91 "-------- day %d --------\n" printf
92 "name, sellIn, quality" print
93 dup Items>> [ Item.ToString print ] each
95 GildedRose.UpdateQuality