新增结点

This commit is contained in:
boyce
2025-10-04 21:23:52 +08:00
parent d4c0bd22ad
commit 3bf19ed329
3 changed files with 307 additions and 6 deletions

View File

@@ -1,6 +1,9 @@
package blueprint
import "fmt"
import (
"fmt"
"math/rand"
)
func init() {
RegExecNode(&AddInt{})
@@ -235,3 +238,60 @@ func (em *ModInt) Exec() (int, error) {
return -1, nil
}
type RandNumber struct {
BaseExecNode
}
func (em *RandNumber) GetName() string {
return "RandNumber"
}
func (em *RandNumber) Exec() (int, error) {
inPortSeed := em.GetInPort(0)
if inPortSeed == nil {
return -1, fmt.Errorf("AddInt inParam 1 not found")
}
inPortMin := em.GetInPort(1)
if inPortMin == nil {
return -1, fmt.Errorf("AddInt inParam 2 not found")
}
inPortMax := em.GetInPort(2)
if inPortMax == nil {
return -1, fmt.Errorf("AddInt inParam 2 not found")
}
outPortRet := em.GetOutPort(0)
if outPortRet == nil {
return -1, fmt.Errorf("AddInt outParam not found")
}
inSeed, ok := inPortSeed.GetInt()
if !ok {
return -1, fmt.Errorf("AddInt inParam 1 not found")
}
inMin, ok := inPortMin.GetInt()
if !ok {
return -1, fmt.Errorf("AddInt inParam 2 not found")
}
inMax, ok := inPortMax.GetInt()
if !ok {
return -1, fmt.Errorf("AddInt inParam 2 not found")
}
var ret int64
if inSeed > 0 {
r := rand.New(rand.NewSource(inSeed))
if r == nil {
return -1, fmt.Errorf("RandNumber fail")
}
ret = int64(r.Intn(int(inMax-inMin+1))) + inMin
} else {
ret = int64(rand.Intn(int(inMax-inMin+1))) + inMin
}
outPortRet.SetInt(ret)
return -1, nil
}

View File

@@ -48,6 +48,24 @@ func (en *execNode) GetInPortDefaultValue(index int) any {
return v
}
func (en *execNode) GetInPortDefaultIntArrayValue(index int) []int64 {
val := en.GetInPortDefaultValue(index)
if val == nil {
return nil
}
return val.([]int64)
}
func (en *execNode) GetInPortDefaultStringArrayValue(index int) []string {
val := en.GetInPortDefaultValue(index)
if val == nil {
return nil
}
return val.([]string)
}
func (en *execNode) Next() *execNode {
if en.nextIdx >= len(en.nextNode) {
return nil

View File

@@ -3,6 +3,7 @@ package blueprint
import (
"fmt"
"github.com/duanhf2012/origin/v2/log"
"math/rand/v2"
)
// 系统入口ID定义1000以内
@@ -173,16 +174,16 @@ func (em *GetArrayString) GetName() string {
func (em *GetArrayString) Exec() (int, error) {
inPort := em.GetInPort(0)
if inPort == nil {
return -1, fmt.Errorf("GetArrayInt inParam not found")
return -1, fmt.Errorf("GetArrayInt inParam 0 not found")
}
outPort := em.GetOutPort(0)
if outPort == nil {
return -1, fmt.Errorf("GetArrayInt outParam not found")
return -1, fmt.Errorf("GetArrayInt outParam 0 not found")
}
arrIndexPort := em.GetInPort(1)
if arrIndexPort == nil {
return -1, fmt.Errorf("GetArrayInt arrIndexParam not found")
return -1, fmt.Errorf("GetArrayInt arrIndexParam 1 not found")
}
arrIndex, ok := arrIndexPort.GetInt()
if !ok {
@@ -214,13 +215,235 @@ func (em *GetArrayLen) GetName() string {
func (em *GetArrayLen) Exec() (int, error) {
inPort := em.GetInPort(0)
if inPort == nil {
return -1, fmt.Errorf("GetArrayInt inParam not found")
return -1, fmt.Errorf("GetArrayInt inParam 0 not found")
}
outPort := em.GetOutPort(0)
if outPort == nil {
return -1, fmt.Errorf("GetArrayInt outParam not found")
return -1, fmt.Errorf("GetArrayInt outParam 0 not found")
}
outPort.SetInt(inPort.GetArrayLen())
return -1, nil
}
type BoolIf struct {
BaseExecNode
}
func (em *BoolIf) GetName() string {
return "BoolIf"
}
func (em *BoolIf) Exec() (int, error) {
inPort := em.GetInPort(1)
if inPort == nil {
return -1, fmt.Errorf("GetArrayInt inParam 1 not found")
}
ret, ok := inPort.GetBool()
if !ok {
return -1, fmt.Errorf("BoolIf inParam error")
}
if ret {
return 1, nil
}
return 0, nil
}
type GreaterThanInteger struct {
BaseExecNode
}
func (em *GreaterThanInteger) GetName() string {
return "GreaterThanInteger"
}
func (em *GreaterThanInteger) Exec() (int, error) {
inPortEqual := em.GetInPort(1)
if inPortEqual == nil {
return -1, fmt.Errorf("GreaterThanInteger inParam 1 not found")
}
inPortA := em.GetInPort(2)
if inPortA == nil {
return -1, fmt.Errorf("GreaterThanInteger inParam 1 not found")
}
inPorB := em.GetInPort(3)
if inPorB == nil {
return -1, fmt.Errorf("GreaterThanInteger inParam 1 not found")
}
ret, ok := inPortEqual.GetBool()
if !ok {
return -1, fmt.Errorf("GreaterThanInteger inParam 1 error")
}
inA, ok := inPortA.GetInt()
if !ok {
return -1, fmt.Errorf("GreaterThanInteger inParam 2 error")
}
inB, ok := inPorB.GetInt()
if !ok {
return -1, fmt.Errorf("GreaterThanInteger inParam 3 error")
}
if ret {
if inA >= inB {
return 1, nil
}
return 0, nil
}
if inA > inB {
return 1, nil
}
return 0, nil
}
type LessThanInteger struct {
BaseExecNode
}
func (em *LessThanInteger) GetName() string {
return "LessThanInteger"
}
func (em *LessThanInteger) Exec() (int, error) {
inPortEqual := em.GetInPort(1)
if inPortEqual == nil {
return -1, fmt.Errorf("GreaterThanInteger inParam 1 not found")
}
inPortA := em.GetInPort(2)
if inPortA == nil {
return -1, fmt.Errorf("GreaterThanInteger inParam 1 not found")
}
inPorB := em.GetInPort(3)
if inPorB == nil {
return -1, fmt.Errorf("GreaterThanInteger inParam 1 not found")
}
ret, ok := inPortEqual.GetBool()
if !ok {
return -1, fmt.Errorf("GreaterThanInteger inParam 1 error")
}
inA, ok := inPortA.GetInt()
if !ok {
return -1, fmt.Errorf("GreaterThanInteger inParam 2 error")
}
inB, ok := inPorB.GetInt()
if !ok {
return -1, fmt.Errorf("GreaterThanInteger inParam 3 error")
}
if ret {
if inA <= inB {
return 1, nil
}
return 0, nil
}
if inA < inB {
return 1, nil
}
return 0, nil
}
type EqualInteger struct {
BaseExecNode
}
func (em *EqualInteger) GetName() string {
return "EqualInteger"
}
func (em *EqualInteger) Exec() (int, error) {
inPortA := em.GetInPort(1)
if inPortA == nil {
return -1, fmt.Errorf("GreaterThanInteger inParam 1 not found")
}
inPorB := em.GetInPort(2)
if inPorB == nil {
return -1, fmt.Errorf("GreaterThanInteger inParam 1 not found")
}
inA, ok := inPortA.GetInt()
if !ok {
return -1, fmt.Errorf("GreaterThanInteger inParam 2 error")
}
inB, ok := inPorB.GetInt()
if !ok {
return -1, fmt.Errorf("GreaterThanInteger inParam 3 error")
}
if inA == inB {
return 1, nil
}
return 0, nil
}
type RangeCompare struct {
BaseExecNode
}
func (em *RangeCompare) GetName() string {
return "RangeCompare"
}
func (em *RangeCompare) Exec() (int, error) {
inPortA := em.GetInPort(1)
if inPortA == nil {
return -1, fmt.Errorf("GreaterThanInteger inParam 1 not found")
}
ret, ok := inPortA.GetInt()
if !ok {
return -1, fmt.Errorf("GreaterThanInteger inParam 1 error")
}
intArray := em.execNode.GetInPortDefaultIntArrayValue(2)
if intArray == nil {
return 0, nil
}
for i := range intArray {
if intArray[i] <= ret {
return i + 2, nil
}
}
return 0, nil
}
type Probability struct {
BaseExecNode
}
func (em *Probability) GetName() string {
return "Probability"
}
func (em *Probability) Exec() (int, error) {
inPortProbability := em.GetInPort(1)
if inPortProbability == nil {
return -1, fmt.Errorf("GreaterThanInteger inParam 1 not found")
}
inProbability, ok := inPortProbability.GetInt()
if !ok {
return -1, fmt.Errorf("GreaterThanInteger inParam 1 error")
}
if inProbability > rand.Int64N(10000) {
return 1, nil
}
return 0, nil
}